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:
- SQL Server Management Studio's Import Data feature
- Create an empty database
- Tasks -> Import Data...
- .NET Framework Data Provider for Odbc
- Valid DSN (verified it connects)
- Copy data from one or more tables or views
- Check 1 VERY simple table
- Click Preview
- 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 the开发者_开发问答n 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.
Microsoft SQL Server Migration Assistant for MySQL v1.0 http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=14280
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.
This is really old now, but if you use MySQL Connector NET and set SQL Server Mode = true in the connection string, this will resolve your error.
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.
Install Chrome : Since internet explorer has some security, install chrome.
Install Microsoft SQL Server Migration Assistant v6.0.1 for MySQL https://www.microsoft.com/en-us/download/details.aspx?id=51218
Install Third Party MySql ODBC Driver 5.1.13 https://dev.mysql.com/downloads/connector/odbc/5.1.html
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
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.
- Export the file from MySQL to a CSV file.
- Export the create statements for the tables from MySQL
- Cry.
3a. Disable foreign key checks in SQL server - Tune the create statements in SQLserver until they work.
- 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
Had similiar issue about this error 42000, and for me I figured out that setting the MySQL global mode to ansi_quotes would solve it:
set global sql_mode=ansi_quotes;
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.
精彩评论