开发者

ASP.NET 4 C# - Import MySQL Data Dump

开发者 https://www.devze.com 2023-02-19 06:16 出处:网络
I have the great joy of being forced to import data from an old system into our new system.The old system uses MySQL and the new one is using MS SQL Server.Unfortunately, I only have access to a data

I have the great joy of being forced to import data from an old system into our new system. The old system uses MySQL and the new one is using MS SQL Server. Unfortunately, I only have access to a data dump (.sql) from MySQL 开发者_Go百科db. Basically I need to be able to create a C# process that will export all the records from the .sql file and save them into our new database. There is binary images and videos kept in the MySQL db but I think once I get to parsing the .sql file I can figure that out.

Is there example code on how to connect and successfully parse a .sql MySQL data dump using C#? I put ASP.NET in the title as that's what I'm using to build the site, but I'm sure this will need to be a nightly process (they're keeping the old system and it needs to be imported nightly).

If this is covered in another Stack Overflow question please point me in the direction. I didn't find anything in my initial search.

Thanks for your help!


Run the MySQL dump using the compatibility option set to mssql. The resulting dump file is simply a script that creates the required objects and bulk inserts data. With the --compatible=mssql option you should then be able to run the script in Microsoft SQL Management Studio (assuming it isn't too large). For example:

mysql -u username -p -h localhost --compatible=mssql DATA-BASE-NAME < data.sql

You can then run this as a cron job nightly if necessary.

0

精彩评论

暂无评论...
验证码 换一张
取 消