简体   繁体   中英

Migrate Data and Schema from MySQL to SQL Server

Are there any free solutions for automatically migrating a database from MySQL to SQL Server Server that "just works"?

I've been attempting this simple (at least I thought so) task all day now. I've tried:

  1. SQL Server Management Studio's Import Data feature
  2. Create an empty database
  3. Tasks -> Import Data...
  4. .NET Framework Data Provider for Odbc
  5. Valid DSN (verified it connects)
  6. Copy data from one or more tables or views
  7. Check 1 VERY simple table
  8. Click Preview
  9. Get Error:

The preview data could not be retrieved. ADDITIONAL INFORMATION: ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.45-community]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"table_name"' at line 1 (myodbc5.dll)

A similar error occurs if I go through the rest of the wizard and perform the operation. The failed step is "Setting Source Connection" the error refers to retrieving column information and then lists the above error. It can retrieve column information just fine when I modify column mappings so I really don't know what the issue is.

I've also tried getting various MySql tools to output ddl statements that SQL Server understand but haven't succeeded.

I've tried with MySQL v5.1.11 to SQL Server 2005 and with MySQL v5.1.45 to SQL Server 2008 (with ODBC drivers 3.51.27.00 and 5.01.06.00 respectively)

There are two free toolkits provided by Microsoft.

  1. Microsoft SQL Server Migration Assistant for MySQL v1.0 http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14280

  2. Microsoft SQL Server Migration Assistant for MySQL v5.1 http://www.microsoft.com/download/en/details.aspx?id=26712

I have used only the second one and it worked for me without any glitch. It required registration with Microsoft for downloading a license file. But it is free to use for everyone.

现在这已经很老了,但是如果你使用MySQL Connector NET并在连接字符串中设置SQL Server Mode = true,这将解决你的错误。

Recently, I have successfully migrated the MySQL database to MSSQL database . Below are detailed steps:

Operating System: AWS Microsoft Windows Server 2012 R2 with SQL Server Standard

Tools Used:

  • SQL Server 2014 Management Studio SQL Developer,
  • Microsoft SQL Server Migration Assistant v6.0.1 for MySQL,
  • Remote Desktop Client, and
  • Third Party MySql ODBC Driver 5.1.13

1. Setup AWS Windows Server 在此输入图像描述

2. From the AWS console ec2 instance list, right click on the windows server and select connect. You would see the similar screen below. 在此输入图像描述

3. Click on the Get Password button which will be required for Remote Desktop connection[#4] and follow the instructions.

4. Connect to that EC2[#1] instance with the Remote Desktop Client by default available in your Ubuntu local machine. Use the credentials from #2. 在此输入图像描述

5. Once you get connected using the remote client, you should be able to access the remote MSSQL server. Install the following tools.

6. Configure ODBC Data Sources(64-bit) :

  • Open Administrative tools → click on ODBC Data Sources(64-bit) and follow the steps to connect to MySQL database.

7. Open SQL Server 2014 Management Studio SQL Developer and connect using windows authentication.

  • Create destination MSSql database for MySql migration.

8. Open Microsoft SQL Server Migration Assistant : For detail visit this link: https://blogs.msdn.microsoft.com/ssma/2011/02/07/mysql-to-sql-server-migration-how-to-use-ssma/

  • Create new project
  • Connect to MySql
  • Connect to MSSql
  • Convert Schema
  • Migrate Data

8. You might have some problem listed here. Please read in detail where I have written the detail resolution. MySql 5.6 to MSSql server 2014 migration : ExecuteReader requires an open and available Connection

There are commercial solutions, but not free solutions. Depending on complexity of your database, rewriting SQL for target dialect can be trivial task - or a very hard one. Rewriting CREATE TABLE statements is never hard, it can be done by hand with no surprises. Procedures, functions and triggers are problematic.

I am afraid there is no simple solution. SQL used in MySQL and T-SQL used in SQL Server 200X are different dialects of SQL. It is not only simple changing say "auto_increment" to "identity", but reserved words that creates a problem. For example

   CREATE TABLE test (
 user varchar(50)
  )

will work in MySQL and fail in SQL Server 2008. To cut long story short - unfortunately, you will need to do it by hand.

  1. Export the file from MySQL to a CSV file.
  2. Export the create statements for the tables from MySQL
  3. Cry.
    3a. Disable foreign key checks in SQL server
  4. Tune the create statements in SQLserver until they work.
  5. Import the CSV files in to MySQL.
    5a. Enable foreign key checks in SQL server.

Also see these answers: migrate-from-mysql-to-sql-server-2008

有关于此错误42000的类似问题,对我来说,我发现将MySQL全局模式设置为ansi_quotes将解决它:

set global sql_mode=ansi_quotes;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM