简体   繁体   中英

MySQL dump compatible is not working

Am I doing something wrong? This command will not work. I'm trying to move from MySQL to PostgreSQL.

mysql> mysqldump --compatible=postgresql dbname > /tmp/table.sql;

I keep getting an error.

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'mysqldump --compatible=postgresql dbname < /tmp/table.sql' at line 1

What am I doing wrong? Is there an easier way to convert the DB? I've read a ton of migration articles but this seems to be the eaiser way to get started with conversion.

Don is quite right about the immediate problem. There's more to it than that, though.

MySQL's mysqldump compatible mode isn't going to produce DDL that you can directly and simply load into other databases. There's no generic and portable way to express things like AUTO_INCREMENT so the dump has to keep MySQL-specific features like that or replace them with an int type without auto-increment behavior. Either way you'll have to edit the dump to replace the old AUTO_INCREMENT field with a SERIAL pseudo-type field.

There are differences in type names between MySQL and PostgreSQL that you're likely to have to correct for as well.

I general, I recommend that you do two dumps from MySQL. One should be a schema-only dump, and one should be a data-only dump, both in "compatible" format. You should then edit the schema dump to correct the MySQL-isms and transform them into PostgreSQL-isms or (where possible) SQL-standard usage. Once you've got the schema fixed up and succssfully loaded into PostgreSQL using psql thedatabasename < schema-edited-for-pg.sql you can load the data dump.

I'd also recommend wrapping the data dump in BEGIN; and END; statements so it either all succeeds or all fails. That'll save you the hassle of having to repeatedly drop and re-create the database and schema whenever if you hit an error part way through the dump and have to go edit the dump to fix it up.

mysqldump is a program that runs from the os command line NOT the mysql command line. quit mysql and execute it there and it should be fine.

我通常出于这种目的使用诸如openDbCopyESF Data Migration Toolkit之类的迁移器工具 ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM