The postings on this site are my own and do not represent my Employer's positions, advice or strategies.

LifeAsBob - Blog

 

Home

No Ads ever, except search!
Friday, April 19, 2024 Login
Public

MySQL Dump File to SQL Server 3/13/2008 10:23:30 AM

MySQL Dump File to SQL Server.  Some how I thought this would be easy, while it was not overly difficult it did require some basic skills, parsing.  I ended up not taking this as far as I wanted, but all i needed was a down and dirty import of a mysql dump file into sql server.  There are many ways to do this, the best two options are to (purchase a utility) or (install mysql, import the dump file, create a proper export that sql server can read and/or an ssis package).  I didn't want to install mysql or purchase a utility. 

 

I wrote a c# program that parses the dump file out into a DDL and DML File.  I than took the DDL File imported it into Erwin as a mysql database, than changed the database to SQL Server and forward engineered the schema to a TSQL Script file.  I then created a SQL Server database off of the TSQL Script file.  Next I ran the TSQL DML File against the database, and poof, i'm done. 

 

This example will not work for every mysql dump file, nor did i perform lots of testing, i just needed something converted.  It is not pretty code.  But maybe it can help you...

 

There was some interesting bits in here; reversing a string, parsing a file one byte at a time and evaluating the byte, word breaking analysis and word grouping.

 

The resulting files still needed a little cleanup, but it was very easy.  The DDL File had one data type that erwin didn't recognize.  The dml file has some extraneous data from the parse, but it is easily removed.

 

I've included examples of the source dump file i used, and the resulting ddl and dml files.

DDL_Output.txt (2.8 KB)
mysql_dump.txt (121.02 KB)
DML_Output.txt (207.73 KB)

 


Blog Home