5,665,355 members and growing! (15,234 online)
Email Password   helpLost your password?
Database » Database » SQL Server     Beginner License: The Code Project Open License (CPOL)

Migrate MySQL to Microsoft SQL Server

By Niklas Henricson

Migrate MySQL to Microsoft SQL Server in just a few simple steps
SQL, Windows, SQL Server (SQL 2005, SQL Server)

Posted: 5 Sep 2008
Updated: 5 Sep 2008
Views: 4,736
Bookmarked: 13 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
4 votes for this Article.
Popularity: 2.31 Rating: 3.83 out of 5
0 votes, 0.0%
1
1 vote, 25.0%
2
0 votes, 0.0%
3
1 vote, 25.0%
4
2 votes, 50.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This article is describing few simple steps in order to migrate a MySQL into Microsoft SQL Server 2005. The technique is very easy, but useful if you plan to move your data from MySQL and upgrade it finally to an MS SQL Server enviroment.

Background

Initially I started my search for an article in Codeproject regarding MySQL->MS SQL migration without any success. I had an old PHPbb forum running, that needed to be upgraded to a Microsoft enviroment entirely. I could have just kept MySQL and Apache server, but instead I decided to migrate the entire concept of PHPbb to a YAF-forum.

Setup ODBC connection to MySQL database

This article will not go through on how to setup a MySQL or MS SQL server, but make sure you have downloaded at least the MySQL ODBC Connector from here: http://dev.mysql.com/downloads/connector/

For this article I downloaded the MySQL ODBC Connector 5.1.

The setup of this connector is pretty simple:

  • Open your ODBC Data Source Administrator from the Control Panel -> Administrative Tools. Under the tab labeled as "System DSN" press the "Add" button.

Setup_ODBC1.jpg

  • On the "Create New Data Source" dialog that appeared, choose MySQL ODBC 5.1 Driver and then press the "Finish" button.

Setup_ODBC2.jpg

  • After that a MySQL connection configuration dialog will appear. Add your MySQL database account information in it, preferably the "root" account which has full access to your databases in MySQL. In this case my database is called "tigerdb". Do not change the port to anything else then 3306, unless during your MySQL server installation have defined something else.

Setup_ODBC3.jpg

  • Press the "Test" button to ensure your connection settings are set properly and then the "OK" button when you're done.

Create a MS SQL link to your MySQL database

In this state you are ready to establish a link towards MySQL database from your Microsoft SQL Server Management Studio. Open a query window and run the following SQL statement:
EXEC master.dbo.sp_addlinkedserver 
@server = N'MYSQL', 
@srvproduct=N'MySQL', 
@provider=N'MSDASQL', 
@provstr=N'DRIVER={MySQL ODBC 5.1 Driver}; SERVER=localhost; DATABASE=tigerdb; USER=root; PASSWORD=hejsan; OPTION=3'
This script will produce a link to your MySQL database through the ODBC connection you just created on the previous stage of this article. The link will appear in the MS SQL Server Management studio like this:

Create_link.jpg

If it doesn't show up in the treeview, press the refresh button.

Import data between the databases

Create a new database in Microsoft SQL Server. I called mine for "testMySQL". In the query window run the following SQL statement to import table shoutbox from the MySQL database tigerdb, into the newly created database in MS SQL called testMySQL.

SELECT * INTO testMySQL.dbo.shoutbox
FROM openquery(MYSQL, 'SELECT * FROM tigerdb.shoutbox')

Thats it!

Points of Interest

During this migration I had to import lately my newly migrated database into the structure of "Yet Another Forum" tables. For that I used a series of SQL-scripts. However I am not going to post them here. If folks leave comments here about the need to these script, just tell me and I will gladly change this article and start adding them. You're welcome to post your comments.

Another issue you will most likely encounter are the differences between these two databases based on datatypes. I would suggest to proceed with a reverse engineering of your MySQL database (for example, Visio is one application that provides reverse engineering functionality) and start mapping all the differences and potential risks of loosing parts of data for instance, within varchar columns.

Microsoft SQL datatypes: http://msdn.microsoft.com/en-us/library/aa258271.aspx

MySQL datatypes: http://dev.mysql.com/tech-resources/articles/visual-basic-datatypes.html

History

2008-09-05: First version of this article.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Niklas Henricson


Niklas Henricson began with programming in 1999 by working for the Swedish Working Life Enviroment authority.

Since then, he has been involved in numerous projects involving MTS/COM+, VB 6.0, ISE Eiffel 4.5, ASP.NET/C#/VB.NET as well as common ASP, and finally database enviroments based on Oracle, MySQL and MS SQL.

Between April and December 2007, Niklas worked as consultant for Mandator AB with some of his assignments spended in Ericsson.

Today he's working as system developer for Mantacore AB, which is a company providing solutions for insurance companies in Europe based in .NET. Niklas has also been working extended periods of time with MS SQL Server programming and Crystal Reports.

In his free time he is refereeing in soccer, scuba diving, is an amateur astronomer and plays saxophone/clarinet for a big band.

One of his most favorite books regarding programming is "The Pragmatic Programmer". Something he is recommending everyone to read.
Occupation: Web Developer
Company: Mantacore Softwise AB
Location: Sweden Sweden

Other popular Database articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 12 of 12 (Total in Forum: 12) (Refresh)FirstPrevNext
GeneralErrormemberMember 21948783:24 5 Nov '08  
GeneralIt worked!!membercullio22:51 21 Oct '08  
GeneralProblem adding linked servermemberDavid Haysom15:09 10 Oct '08  
GeneralRe: Problem adding linked servermemberNiklas Henricson23:43 12 Oct '08  
GeneralRe: Problem adding linked servermemberDavid Haysom22:22 18 Oct '08  
GeneralWhy use SSMS?memberneilio8:23 11 Sep '08  
GeneralRe: Why use SSMS? [modified]memberNiklas Henricson9:28 11 Sep '08  
GeneralRe: Why use SSMS?memberneilio10:46 11 Sep '08  
GeneralJust what I neededmemberAceisback8:38 6 Sep '08  
GeneralRe: Just what I needed [modified]memberNiklas Henricson21:20 7 Sep '08  
GeneralRe: Just what I neededmemberAceisback13:45 8 Sep '08  
GeneralRe: Just what I neededmemberNiklas Henricson20:12 8 Sep '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 5 Sep 2008
Editor:
Copyright 2008 by Niklas Henricson
Everything else Copyright © CodeProject, 1999-2008
Web19 | Advertise on the Code Project