Click here to Skip to main content
15,390,185 members
Articles / Database Development / SQL Server
Posted 5 Sep 2008


66 bookmarked

Migrate MySQL to Microsoft SQL Server

Rate me:
Please Sign up or sign in to vote.
4.87/5 (43 votes)
5 Sep 2008CPOL3 min read
Migrate MySQL to Microsoft SQL Server in just a few simple steps


This article describes a few simple steps in order to migrate 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 a Microsoft SQL Server environment.


Initially, I started my search for an article on CodeProject regarding MySQL->MS SQL migration without any success. I had an old PHPbb forum running, that needed to be upgraded to a Microsoft environment 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 how to setup a MySQL or Microsoft SQL server, but make sure you have downloaded at least the MySQL ODBC Connector from here.

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 labelled as "System DSN", press the "Add" button.


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


  • 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 other than 3306, unless during your MySQL server installation, you have defined something else.


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

Create a Microsoft 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', 
@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 in the previous stage of this article. The link will appear in the Microsoft SQL Server Management Studio like this:


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 "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 Microsoft SQL called testMySQL.

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

That's 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 for these scripts, 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 losing parts of data for instance, within varchar columns.

Microsoft SQL datatypes:

MySQL datatypes:


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


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


About the Author

Niklas Henricson
Software Developer (Senior) TEKSystems
United States United States
I started my journey with programming 1999 by working for the Swedish Working Life Enviroment authority.

Since then, I've been involved in numerous projects and jobs 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 2007 and December 2008, I worked as consultant for Mandator AB with some of my assignments at Ericsson ST in Stockholm.

In 2009 I moved to south Sweden where I continued working as an IT consultant at Cybergroup Group South AB with assignments at Sony Ericsson, Swedish Institute for Infectious Disease Control and other in-house projects.

Today, I work for CGI with several different assignments in various projects within .NET Development.

One of my most favorite books in regards to programming is "The Pragmatic Programmer". Something that I definetely recommend for everyone to read.

My LinkedIn is:

Comments and Discussions

SuggestionQuerying Linkedserver Pin
SreedharV27-Aug-19 11:09
MemberSreedharV27-Aug-19 11:09 
PraiseThats IT Pin
Member 139345141-Aug-18 8:40
MemberMember 139345141-Aug-18 8:40 
QuestionYou my hero Pin
Ovie Prince Tegaton2-May-17 22:06
professionalOvie Prince Tegaton2-May-17 22:06 
Questionrefreshing data once in a day Pin
Member 1191400616-Aug-15 22:45
MemberMember 1191400616-Aug-15 22:45 
Questionhow to export mysql data to MS sql 2008r2 Pin
kanthasamy8-Jun-15 23:41
Memberkanthasamy8-Jun-15 23:41 
QuestionMigrate multiples tables Pin
JorgeSanzRi15-Dec-14 1:09
MemberJorgeSanzRi15-Dec-14 1:09 
Questioni am getting an error while doing the above process. Pin
Member 10851839 14321-Sep-14 23:56
MemberMember 10851839 14321-Sep-14 23:56 
QuestionChecks on New Database created from Mysql Pin
Member 78961363-Sep-14 3:13
MemberMember 78961363-Sep-14 3:13 
QuestionCan we convert stored procedure from ms sql server to mysql Pin
Priyant Jain17-Mar-14 19:28
MemberPriyant Jain17-Mar-14 19:28 
AnswerRe: Can we convert stored procedure from ms sql server to mysql Pin
Member 1096601623-Jul-14 3:01
MemberMember 1096601623-Jul-14 3:01 
GeneralRe: Can we convert stored procedure from ms sql server to mysql Pin
Member 1390530014-Jul-18 22:12
MemberMember 1390530014-Jul-18 22:12 
QuestionCompare to SSMA Pin
dsa4230-Oct-13 9:49
Memberdsa4230-Oct-13 9:49 
AnswerRe: Compare to SSMA Pin
dsa4230-Oct-13 10:07
Memberdsa4230-Oct-13 10:07 
GeneralMySQL client ran out of memory Pin
Hninn Pwint Phyu8-Aug-13 18:16
MemberHninn Pwint Phyu8-Aug-13 18:16 
GeneralRe: MySQL client ran out of memory Pin
Niklas Henricson9-Aug-13 20:57
MemberNiklas Henricson9-Aug-13 20:57 
GeneralRe: MySQL client ran out of memory Pin
Hninn Pwint Phyu9-Aug-13 21:05
MemberHninn Pwint Phyu9-Aug-13 21:05 
GeneralRe: MySQL client ran out of memory Pin
Niklas Henricson9-Aug-13 21:19
MemberNiklas Henricson9-Aug-13 21:19 
GeneralRe: MySQL client ran out of memory Pin
Hninn Pwint Phyu14-Aug-13 21:56
MemberHninn Pwint Phyu14-Aug-13 21:56 
GeneralData Type Issue Pin
satz mois24-Jul-13 5:14
Membersatz mois24-Jul-13 5:14 
GeneralRe: Data Type Issue Pin
satz mois25-Jul-13 19:24
Membersatz mois25-Jul-13 19:24 
GeneralRe: Data Type Issue Pin
Niklas Henricson9-Aug-13 20:59
MemberNiklas Henricson9-Aug-13 20:59 
GeneralMy vote of 4 Pin
Abhishek Durvasula17-Jul-13 20:32
MemberAbhishek Durvasula17-Jul-13 20:32 
GeneralRe: My vote of 4 Pin
Niklas Henricson9-Aug-13 20:58
MemberNiklas Henricson9-Aug-13 20:58 
QuestionError When Testing the Connection from SQL Server Management Studio Pin
Member 78247973-Jun-13 9:12
MemberMember 78247973-Jun-13 9:12 
QuestionBro you are a F*&(ng Legend!! Pin
Robert James Battam23-May-13 19:36
MemberRobert James Battam23-May-13 19:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.