Can you automatically create a mysqldump file that doesn't enforce foreign key constraints?

前端 未结 5 1954
深忆病人
深忆病人 2020-12-05 06:23

When I run a mysqldump command on my database and then try to import it, it fails as it attempts to create the tables alphabetically, even though they may have a foreign key

5条回答
  •  [愿得一人]
    2020-12-05 06:50

    Beware of your MySQL client you use, with the mysql command, no problem. Dumping:

    % mysqldump -u ocp6 -pocp6 ocp6 --single-transaction --result-file=dump.sql 
    

    Restoring:

    % mysql -u ocp6 -pocp6 ocp6 < dump.sql
    

    Everything's fine.

    With the use of another MySQL client (mycli in my situation) to restore the dump-file:

    mysql ocp6@:(none)> \. dump.sql
    […]
    (1005, 'Can\'t create table `ocp6`.`composition` (errno: 150 "Foreign key constraint is incorrectly formed")')
    

    I assume that mycli do not understand conditional comments.

提交回复
热议问题