将SQL数据库从MySql(phpmyadmin)迁移到MSSQL(sql express)

时间:2018-01-03 17:26:16

标签: mysql sql-server database

最近我一直在从普通的php迁移到ASP.NET。由于我不再使用PHP,我认为最好将MSSQL与sql express一起使用,而不是使用phpmyadmin坚持使用MySql。

我有一个MySql数据库,我想转移到sql express。有没有方便的方法呢?

我已经尝试将数据库导出到sql文件,但是在SSMS中打开脚本时会出现很多错误。我试图解决它们,但我甚至不了解它们中的大多数。

这是我正在使用的sql文件: (这里没有敏感数据,所有密码都是占位符。)

   -- phpMyAdmin SQL Dump
-- version 4.6.4
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Jan 03, 2018 at 04:55 PM
-- Server version: 5.7.14
-- PHP Version: 7.0.10

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `virtual-congress`
--

-- --------------------------------------------------------

--
-- Table structure for table `args_votes`
--

CREATE TABLE `args_votes` (
  `arg` int(11) NOT NULL,
  `user` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `args_votes`
--

INSERT INTO `args_votes` (`arg`, `user`) VALUES
(6, 6),
(7, 6);

-- --------------------------------------------------------

--
-- Table structure for table `arguments`
--

CREATE TABLE `arguments` (
  `id` int(11) NOT NULL,
  `repTo` int(11) NOT NULL,
  `issue` int(11) NOT NULL,
  `user` int(11) NOT NULL,
  `argument` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `arguments`
--

INSERT INTO `arguments` (`id`, `repTo`, `issue`, `user`, `argument`) VALUES
(1, -1, 1, 4, 'This is a test argument.'),
(2, 1, 1, 1, 'This is a test reply.'),
(3, 2, 1, 1, 'This is a test nested reply'),
(4, 1, 1, 1, 'This is a another test reply.'),
(5, -1, 1, 1, 'This is another test argument'),
(6, -1, 1, 5, 'sorry for the spam'),
(9, -1, 1, 5, 'sorry for the spam again./');

-- --------------------------------------------------------

--
-- Table structure for table `categories`
--

CREATE TABLE `categories` (
  `id` int(11) NOT NULL,
  `name` tinytext NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `categories`
--

INSERT INTO `categories` (`id`, `name`) VALUES
(1, 'Policy'),
(2, 'Foreign Policy'),
(3, 'Society'),
(4, 'Economics'),
(5, 'Other');

-- --------------------------------------------------------

--
-- Table structure for table `issues`
--

CREATE TABLE `issues` (
  `id` int(11) NOT NULL,
  `title` text NOT NULL,
  `issue` text NOT NULL,
  `subject` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `issues`
--

INSERT INTO `issues` (`id`, `title`, `issue`, `subject`) VALUES
(1, 'What regulations should be placed on buying guns?', 'This is just a test issue.', 1),
(2, 'How strong should Restrictions on Animal Testing be?', 'This is  a test issue.', 1);

-- --------------------------------------------------------

--
-- Table structure for table `options`
--

CREATE TABLE `options` (
  `id` int(11) NOT NULL,
  `issue` int(11) NOT NULL,
  `title` text NOT NULL,
  `text` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `options`
--

INSERT INTO `options` (`id`, `issue`, `title`, `text`) VALUES
(1, 1, 'No Regulations', 'Everyone should be able to buy guns, as if it was water.'),
(2, 1, 'Semi-Strict Regulation', 'Some people should not be able to buy guns, and a license must be acquired through tests.'),
(3, 1, 'Strict Regulations', 'Getting a gun should be very hard, and only professionals will have the right to hold a firearm.');

-- --------------------------------------------------------

--
-- Table structure for table `options_votes`
--

CREATE TABLE `options_votes` (
  `opt` int(11) NOT NULL,
  `user` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

-- --------------------------------------------------------

--
-- Table structure for table `parties`
--

CREATE TABLE `parties` (
  `id` int(11) NOT NULL,
  `name` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `parties`
--

INSERT INTO `parties` (`id`, `name`) VALUES
(1, 'The Test Party'),
(2, 'The Stupid Party');

-- --------------------------------------------------------

--
-- Table structure for table `subjects`
--

CREATE TABLE `subjects` (
  `id` int(11) NOT NULL,
  `name` tinytext NOT NULL,
  `categ` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `subjects`
--

INSERT INTO `subjects` (`id`, `name`, `categ`) VALUES
(1, 'Regulations', 1),
(2, 'Law', 1),
(3, 'Middle East', 2),
(4, 'World Powers', 2),
(5, 'Africa', 2),
(6, 'Far East', 2),
(7, 'Releigon', 3),
(8, 'Culture', 3),
(9, 'Sports', 3),
(10, 'Taxation', 4);

-- --------------------------------------------------------

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `id` int(11) NOT NULL,
  `username` text NOT NULL,
  `email` text NOT NULL,
  `password` text NOT NULL,
  `power` int(11) NOT NULL DEFAULT '1'
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `username`, `email`, `password`, `power`) VALUES
(1, 'test', 'test@gmail.com', '123', 1),
(3, 'test2', 'test2@gmail.com', '123', 1),
(4, 'test3', 'test3@gmail.com', '123', 1),
(5, 'test4', 'test4@gmail.com', '1234', 2);

-- --------------------------------------------------------

--
-- Table structure for table `user_party`
--

CREATE TABLE `user_party` (
  `user` int(11) NOT NULL,
  `party` int(11) NOT NULL,
  `id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

--
-- Dumping data for table `user_party`
--

INSERT INTO `user_party` (`user`, `party`, `id`) VALUES
(5, 1, 1),
(1, 2, 2);

--
-- Indexes for dumped tables
--

--
-- Indexes for table `arguments`
--
ALTER TABLE `arguments`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `categories`
--
ALTER TABLE `categories`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `issues`
--
ALTER TABLE `issues`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `options`
--
ALTER TABLE `options`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `parties`
--
ALTER TABLE `parties`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `subjects`
--
ALTER TABLE `subjects`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `user_party`
--
ALTER TABLE `user_party`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `arguments`
--
ALTER TABLE `arguments`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
--
-- AUTO_INCREMENT for table `categories`
--
ALTER TABLE `categories`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;
--
-- AUTO_INCREMENT for table `issues`
    --
ALTER TABLE `issues`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `options`
--
ALTER TABLE `options`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT for table `parties`
--
ALTER TABLE `parties`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
--
-- AUTO_INCREMENT for table `subjects`
--
ALTER TABLE `subjects`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
--
-- AUTO_INCREMENT for table `user_party`
--
ALTER TABLE `user_party`

  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

1 个答案:

答案 0 :(得分:0)

MySQL的SQL方言与SQL Server没有直接兼容,特别是在DDL方面。

您可以尝试SQL Server Migration Assistant,但 需要在迁移后验证您的数据。有更详细的信息here

但是,我见过的大多数迁移完全是手动的。创建新表,将旧表转储为CSV,然后将CSV导入新数据库。

然后,无论您采用哪种方式,都要验证并测试,验证和测试,验证和测试,并保留旧数据库几年,以便在您错过的内容中咬你。老实说,除非你真的需要SQL Server中的功能,否则我可能不会转向它,因为如果你的数据库太大,你可能需要许可它。

相关问题