I had some hard time today as I was trying to migrate a database from MySQL 5.0 to MSSQL Server 2005 Express Edition. First I’ve tried some “free” migration tools. After installation, the programs asked for an activation key, which could be purchased from the developers of the specific tools.
As I was not willing to pay for such a simple task, I looked for some other solutions. The first solution found (using Google) was the one described here. The only inconvenient is that the article tells you how to migrate from MySQL to MSSQL 2000. I’ve read it anyway, hoping that the process will be similar to those of migrating to MSSQL Server 2005. Found out that I need DTS (Data Transformation Services) to complete the migration. I’ve started looking for it or for a similar tool in my MSSQL Server 2005, and I found out that a similar tool, named SSIS (Server Side Includes / SQL Server Integration Services) does exist for MSSQL 2005, but that the tool is not available in the Express Edition (this edition of MSSQL Server is free as in "free beer" and you can download it from here).
Got mad, sent an email to some friends with my problem and continued searching. After a while I found an answer on the MSDN Forums.
You need to use the MySQL ODBC driver (be sure to download the appropriate version for your MySQL Database; the link is for version 3.51) to create a Linked Server to the MySQL Server, and then run a SQL query to copy your database, table by table. The query is (write the database name, server name, user and password specific to your server):
EXEC master.dbo.sp_addlinkedserver @server = N'MYSQL', @srvproduct=N'MySQL', @provider=N'MSDASQL', @provstr=N'DRIVER={MySQL ODBC 3.51 Driver}; SERVER=127.0.0.1; DATABASE=Db_NAME; USER=myusername; PASSWORD=mypass; OPTION=3'
Then you’ll have to copy your database table by table. The code for one of the tables will be:
select * into MSSQL_DB_Name.dbo.TableName
from openquery(MySQL, 'select * from Db_Name.TableName')
Why pay when you can write an application yourself that can do the work?
Technorati tags: Code, MSSQL Server