如何将SQL Server数据库导出到MySQL?
我正在尝试从 SQL Server 数据库备份文件 (.bak
) 转换为 MySQL。 这个问题和答案非常有用,并且我已成功导入数据库,但现在仍坚持导出到 MySQL。
建议使用MySQL Migration Toolkit,但似乎已被MySQL Workbench取代。是否可以使用 MySQL Workbench 以与迁移工具相同的方式从 SQL Server 迁移?
或者迁移工具包是否仍然可用?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
您可以使用 MySQL Workbench,它提供了一种将数据和应用程序从 Microsoft SQL Server 快速迁移到MySQL 花费更少的时间和精力。
该工具具有许多很酷的功能,例如:
阅读更多
http://www.mysql.com/products/workbench/migrate/
You can use MySQL Workbench which provides a way to quickly migrate data and applications from Microsoft SQL Server to MySQL employing less time and effort.
This tool has a lot of cool features like:
Read more
http://www.mysql.com/products/workbench/migrate/
我使用 sqlyog 从 mssql 迁移到 mysql。我尝试了迁移工具包和工作台,但喜欢 sqlyog,因为它的SJA。我可以安排导入过程,并可以使用 WHERE 子句进行增量导入。
I use sqlyog to migrate from mssql to mysql. I tried Migration toolkit and workbench but liked sqlyog for its SJA. I could schedule the import process and could do incremental import using WHERE clause.
PhpMyAdmin 有一个导入向导,可以让您导入 MSSQL 文件类型。
请参阅http://dev.mysql.com/doc/refman/ 5.1/en/sql-mode.html 了解其支持的数据库脚本类型。
PhpMyAdmin has a Import wizard that lets you import a MSSQL file type too.
See http://dev.mysql.com/doc/refman/5.1/en/sql-mode.html for the types of DB scripts it supports.
将其一一转换为 MySQL 查询
如果您有 MSSQL 兼容的 SQL 转储,您可以使用此在线工具http://burrist .com/mstomy.php
希望它节省了您的时间
if you have a MSSQL compatible SQL dump you can convert it to MySQL queries one by one using this online tool
http://burrist.com/mstomy.php
Hope it saved your time
如上所述,如果您的数据中包含制表符、逗号或换行符,那么使用 CSV 导出和导入数据将会非常困难。值将溢出字段,并且您将收到错误。如果任何长字段包含带有换行符的多行文本,这个问题会更严重。
在这些情况下,我的方法是使用 BCP 命令行实用程序从 SQL Server 导出数据,然后使用 MySQL 中的 LOAD DATA INFILE .. INTO TABLE 命令读回数据文件。BCP 是最古老的 SQL Server 之一命令行实用程序(可以追溯到 SQL Server - v6.5 的诞生),但它仍然存在,并且仍然是获取数据的最简单、最可靠的方法之一。
要使用此技术,您需要在 MySQL 中创建具有相同或等效架构的每个目标表。我通过右键单击 SQL 企业管理器中的数据库,然后单击任务 -> 生成脚本... 并为所有表创建 SQL 脚本来完成此操作。然后,您必须手动将脚本转换为 MySQL 兼容的 SQL(这绝对是工作中最糟糕的部分),最后在 MySQL 数据库上运行 CREATE TABLE 命令,这样您就可以按列将表与 SQL Server 版本相匹配,为空并准备好数据。
然后,从MS-SQL端导出数据,如下所示。
(如果您使用的是 SQL Server Express,请使用 -S 值,如下所示: -S "ComputerName\SQLExpress")
这将创建一个名为 TableName.dat 的文件,其中的字段由 ![tab]! 分隔!和由 \0 NUL 字符分隔的行。
现在将 .dat 文件复制到 MySQL 服务器上的 /tmp 并加载到 MySQL 端,如下所示:
不要忘记表(本例中的 TableName)必须已在 MySQL 端创建。
当涉及到转换 SQL 模式时,这个过程是痛苦的手动过程,但是它甚至适用于最困难的数据,并且因为它使用平面文件,所以您永远不需要说服 SQL Server 与 MySQL 对话,反之亦然。
As mentioned above, if your data contains tab characters, commas, or newlines in your data then it's going to be very hard to export and import it with CSV. Values will overflow out of the fields and you will get errors. This problem is even worse if any of your long fields contain multi-line text with newline characters in them.
My method in these cases is to use the BCP command-line utility to export the data from SQL server, then use LOAD DATA INFILE .. INTO TABLE command in MySQL to read the data file back in. BCP is one of the oldest SQL Server command line utilities (dating back to the birth of SQL server - v6.5) but it is still around and still one of the easiest and most reliable ways to get data out.
To use this technique you need to create each destination table with the same or equivalent schema in MySQL. I do that by right clicking the Database in SQL enterprise manager, then Tasks->Generate Scripts... and create a SQL script for all the tables. You must then convert the script to MySQL compatible SQL by hand (definitely the worst part of the job) and finally run the CREATE TABLE commands on the MySQL database so you have matching tables to the SQL server versions column-wise, empty and ready for data.
Then, export the data from the MS-SQL side as follows.
(If you're using SQL Server Express, use a -S value like so: -S "ComputerName\SQLExpress")
That will create a file named TableName.dat, with fields delimited by ![tab]! and rows delimited by \0 NUL characters.
Now copy the .dat files into /tmp on the MySQL server and load on the MySQL side like so:
Don't forget that the tables (TableName in this example) must be created already on the MySQL side.
This procedure is painfully manual when it comes to converting the SQL schema over, however it works for even the most difficult of data and because it uses flat files you never need to persuade SQL Server to talk to MySQL, or vice versa.
您可以使用数据加载器工具轻松完成此操作。在使用这个工具之前我已经这样做过并且发现它很好。
You can do this easily by using Data Loader tool. I have already done this before using this tool and found it good.
看来您是正确的:迁移工具包将与 MySQL Workbench 集成 - 但我认为这还没有完成。请参阅 MySQL GUI 工具(包括迁移工具包)的生命周期终止公告:
http ://www.mysql.com/support/eol-notice.html
MySQL 维护 MySQL GUI 工具包的档案:
http://dev.mysql.com/downloads/gui-tools/5.0.html
It looks like you correct: The Migration Toolkit is due to be integrated with MySQL Workbench - but I do not think this has been completed yet. See the End-of-life announcement for MySQL GUI Tools (which included the Migration Toolkit):
http://www.mysql.com/support/eol-notice.html
MySQL maintain archives of the MySQL GUI Tools packages:
http://dev.mysql.com/downloads/gui-tools/5.0.html
我在 MySQL 迁移工具包的“高级”选项卡上使用以下连接字符串来连接到 SQL Server 2008 实例:
通常该参数具有“systemName\instanceName”。但在上面,不要添加“systemName\”(仅使用 InstanceName)。
要检查 instanceName 应该是什么,请转到 services.msc 并检查 MSSQL 实例的 DisplayName。它显示类似于 MSSQL$instanceName。
希望这对 mysql 迁移工具包的 MSSQL 连接有所帮助。
I used the below connection string on the Advanced tab of MySQL Migration Tool Kit to connect to SQL Server 2008 instance:
Usually the parameter has "systemName\instanceName". But in the above, do not add "systemName\" (use only InstanceName).
To check what the instanceName should be, go to services.msc and check the DisplayName of the MSSQL instance. It shows similar to MSSQL$instanceName.
Hope this help in MSSQL connectivity from mysql migration toolKit.
MySQL 迁移工具包 (1.1.10) 仍可从此处下载:
http://downloads.mysql.com/archives.php?p=MySQLDeveloperSuite&v=1.1.10
MySQL Migration Toolkit (1.1.10) still available for download from here:
http://downloads.mysql.com/archives.php?p=MySQLDeveloperSuite&v=1.1.10
我有一些数据必须从 mssql 获取到 mysql,但很难找到解决方案。所以我最后所做的(有点啰嗦,但作为最后的手段它是有效的)是:
单击左上角框选择整个表格:
将数据复制到剪贴板(ctrl + v)
希望这会有所帮助
I had some data I had to get from mssql into mysql, had difficulty finding a solution. So what I did in the end (a bit of a long winded way to do it, but as a last resort it works) was:
Click the top left corner box to select whole table:
Copy data to clipboard (ctrl + v)
Hope this helps
官方网站上不再提供下载(http://dev.mysql.com /downloads/gui-tools/5.0.html)
相反,请看这里:
http://download.softagency.net/MySQL/Downloads/MySQLGUITools/
downloads are no more available on the official website (http://dev.mysql.com/downloads/gui-tools/5.0.html)
instead, take a look here:
http://download.softagency.net/MySQL/Downloads/MySQLGUITools/