Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / database / SQL-Server / SQL-Server-2008R2

MSSQL to MySQL Export

5.00/5 (1 vote)
16 Apr 2014CPOL 11.9K   30  
Converting MSSQL database to MySQL

Introduction

This piece of code aims to export or convert MSSQL database to MySQL database.

It can be achieved with third party apps.

I'm not very proud of my code, it can be improved but it worked for me.

Background

There are 4 files:

  1. Batch to execute SQLCMD
  2. Table schema export
  3. Data export
  4. FK Export
This script uses information schema to get table/columns information.

It can be customized as you want.

Using the Code

Just update information in .bat file:

C++
rem variables de connexion SQL
set host= your_host (local) or IP,PORT
set schema= your_schema
set user= your_user
set pass= your_password 

Then execute (cmd or click).

3 files are created:

  • tables.sql which contains table definitions
  • data.sql which contains data
  • fk.sql for fk
You will have to do a regex replace (with Notepad++):
  • on table.sql: replace ",\r\n\r\n)" by "\r\n\r\n)"
  • on data.sql: replace ",\r\n\r\n/" by ";\r\n\r\n/"

Points of Interest

My code is a little ugly, but the most interesting thing was to investigate into INFORMATIONS_SCHEMA on MSSQL, and the way to produce another SQL script for MySQL.

License

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