如何将 phpMyAdmin SQL Dump 的查询转换为 SQL Server 清晰的查询

发布于 2024-09-10 05:31:48 字数 223 浏览 2 评论 0原文

我已经开展了一个小项目,该项目已经发展了当前的数据库。应用程序是用php编写的,数据库是mysql。

我正在重写应用程序,但我仍然需要维护数据库的结构和数据。我收到了一个 sql 转储文件。当我尝试在 sql server management studio 中运行它时,我收到许多错误。我想知道有什么办法可以将 sql 脚本从创建的 phpMyAdmin 转储文件转换为 tsql?

有什么想法吗?

I have undertaken a small project which already evolved a current database. The application was written in php and the database was mysql.

I am rewriting the application, yet I still need to maintain the database's structure as well as data. I have received an sql dump file. When I try running it in sql server management studio I receive many errors. I wanted to know what work around is there to convert the sql script from the phpMyAdmin dump file that was created to tsql?

Any Ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜访吸血鬼 2024-09-17 05:31:48

phpMyAdmin 是 MySQL 数据库的前端。转储数据库可以通过多种格式完成,包括SQL脚本代码,但我猜你的问题是你使用的是SQL Server,而T-SQL与MySQL不同。

编辑:我看到原始发帖者意识到了这一点(帖子上没有 MySQL 标签)。我的建议是以 CSV 格式(例如)重新转储数据库,并通过批量插入导入,例如,对于单个表,

CREATE TABLE MySQLData [...]

BULK
INSERT MySQLData
FROM 'c:\mysqldata.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

如果数据库不是太大并且只有几个表,这应该可以正常工作。

顺便说一句,您确实遇到了比运行脚本更多的问题:数据类型的映射绝对不容易。

这是一篇关于迁移 MySQL 的文章 -> SQL Server 通过 DTS 导入/导出向导,如果您的数据库很大(并且您仍然可以访问,即不仅可以转储),这可能是一个好方法。

phpMyAdmin is a front-end for MySQL databases. Dumping databases can be done in various formats, including SQL script code, but I guess your problem is that you are using SQL Server, and T-SQL is different from MySQL.

EDIT: I see the original poster was aware of that (there was no MySQL tag on the post). My suggestion would be to re-dump the database in CSV format (for example) and to import via bulk insert, for example, for a single table,

CREATE TABLE MySQLData [...]

BULK
INSERT MySQLData
FROM 'c:\mysqldata.txt'
WITH
(
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
GO

This should work fine if the database isn't too large and has only few tables.

You do have more problems than making a script run, by the way: Mapping of data types is definitely not easy.

Here is an article about migration MySQL -> SQL Server via the DTS Import/Export wizard, which may well be a good way if your database is large (and you still have access, ie, not only have the dump).

旧瑾黎汐 2024-09-17 05:31:48

Tsql 和 Mysql 之间的语法相差不是一百万英里,您可能可以通过反复试验以及一系列查找和替换来重写它。

更好的选择可能是安装 mysql 和 mysqlconnector,并使用 dubp 文件恢复数据库。

然后,您可以在 SQL 服务器上创建链接服务器并执行一系列查询,如下所示:

SELECT * 
INTO SQLTableName
FROM OPENQUERY
(LinkedServerName, 'SELECT * FROM  MySqlTableName') 

The syntax between Tsql and Mysql is not a million miles off, you could probably rewrite it through trial and error and a series of find and replaces.

A better option would probably be to install mysql and mysqlconnector, and restore the database using the dubp file.

You could then create a Linked Server on the SQL server and do a series of queries like the following:

SELECT * 
INTO SQLTableName
FROM OPENQUERY
(LinkedServerName, 'SELECT * FROM  MySqlTableName') 
昇り龍 2024-09-17 05:31:48

MySQL 的 mysqldump 实用程序可以为其他系统生成某种程度上兼容的转储。例如,使用 --兼容=mssql。此选项不保证与其他服务器的兼容性,但可能会防止大多数错误,从而减少您手动更改的时间。

MySQL's mysqldump utility can produce somewhat compatible dumps for other systems. For instance, use --compatible=mssql. This option does not guarantee compatibility with other servers, but might prevent most errors, leaving less for you to manually alter.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文