从MySQL转储导入数据库-语法错误

时间:2022-07-19 22:47:38

I have a backup mysql file, and I'm trying to import that to my postsql database.

我有一个备份的mysql文件,我正在尝试将它导入到我的postsql数据库中。

/Users/bheng/Desktop/database_backups/2016-06-10-local.sql

I'm trying to do it via a command line.

我试着通过命令行来做。

psql -d db-local -U root -f ~/Desktop/database_backups/2016-06-10-local.sql

I kept getting

我一直在变

从MySQL转储导入数据库-语法错误

I even try log-in to postgress and run this it import fine

我甚至尝试登录到postexit并运行这个it导入。

\i /Users/bheng/Desktop/database_backups/2016-06-10-local.sql

same result happen.

同样的结果发生。

Did I do something wrong ? How do I stop/prevent this ?

我做错什么了吗?我该如何停止/预防?

Any hints / suggestions on this will be much appreciated !

如有任何提示或建议,我们将不胜感激!

2 个解决方案

#1


3  

What worked for me was pgloader. It's very fast + open source under the PostgreSQL License.

对我起作用的是pgloader。它在PostgreSQL许可下是非常快速的+开源的。

The first detail at the top of the website actually mentions migrating from MySQL to PostgreSQL in one command. Good luck!

网站顶部的第一个细节实际上提到了从MySQL迁移到PostgreSQL的一个命令。好运!

Link to the Github repo

链接到Github的repo

#2


0  

For any still looking for answers;
The error has a mysql "back-tick" in it (`). Mysql uses "back-ticks" to keep identifiers like table names safe. Postgres uses a double quotes (").

You can not just take a dump of one sql database vendor and import on another. There are syntax, foreign key, index, data escaping, and etc. issues to deal with.

对于任何仍在寻找答案的人;错误中有一个mysql“后勾”(')。Mysql使用“回勾”来确保表名等标识符的安全性。Postgres使用双引号(“)”。您不能只接受一个sql数据库供应商的转储,而将其导入另一个。有语法、外键、索引、数据转义等问题需要处理。

If you are lucky and you have a simple database, you can get away with using something like "sed" to replace syntax and encoding issues.

如果幸运的话,您有一个简单的数据库,您可以使用“sed”来替换语法和编码问题。

For example, you could have replaced "back-ticks" with double quotes to stop the error you are geeting.

例如,您可以用双引号替换“反勾”,以停止您正在获取的错误。

sed -i 's/`/"/g' /path/to/sql_script

However, I am sure this will just reveal the next issue. It takes time to migrate database vendors. You will probably end up using "sed" or something like it. ODBC and/or JDBC can not handle all of the flat out bad data and unusual cases you may encounter.

然而,我相信这将揭示下一个问题。迁移数据库供应商需要时间。你可能最终会使用“sed”或类似的东西。ODBC和/或JDBC不能处理所有可能遇到的糟糕数据和异常情况。

#1


3  

What worked for me was pgloader. It's very fast + open source under the PostgreSQL License.

对我起作用的是pgloader。它在PostgreSQL许可下是非常快速的+开源的。

The first detail at the top of the website actually mentions migrating from MySQL to PostgreSQL in one command. Good luck!

网站顶部的第一个细节实际上提到了从MySQL迁移到PostgreSQL的一个命令。好运!

Link to the Github repo

链接到Github的repo

#2


0  

For any still looking for answers;
The error has a mysql "back-tick" in it (`). Mysql uses "back-ticks" to keep identifiers like table names safe. Postgres uses a double quotes (").

You can not just take a dump of one sql database vendor and import on another. There are syntax, foreign key, index, data escaping, and etc. issues to deal with.

对于任何仍在寻找答案的人;错误中有一个mysql“后勾”(')。Mysql使用“回勾”来确保表名等标识符的安全性。Postgres使用双引号(“)”。您不能只接受一个sql数据库供应商的转储,而将其导入另一个。有语法、外键、索引、数据转义等问题需要处理。

If you are lucky and you have a simple database, you can get away with using something like "sed" to replace syntax and encoding issues.

如果幸运的话,您有一个简单的数据库,您可以使用“sed”来替换语法和编码问题。

For example, you could have replaced "back-ticks" with double quotes to stop the error you are geeting.

例如,您可以用双引号替换“反勾”,以停止您正在获取的错误。

sed -i 's/`/"/g' /path/to/sql_script

However, I am sure this will just reveal the next issue. It takes time to migrate database vendors. You will probably end up using "sed" or something like it. ODBC and/or JDBC can not handle all of the flat out bad data and unusual cases you may encounter.

然而,我相信这将揭示下一个问题。迁移数据库供应商需要时间。你可能最终会使用“sed”或类似的东西。ODBC和/或JDBC不能处理所有可能遇到的糟糕数据和异常情况。