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

Posted by Tai Squared on Stack Overflow See other posts from Stack Overflow or by Tai Squared
Published on 2010-03-12T00:17:51Z Indexed on 2010/03/12 0:37 UTC
Read the original article Hit count: 268

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 that references a table later in the file. There doesn't appear to be anything in the documentation and I've found answers like this that say to update the file after it's created to include:

set FOREIGN_KEY_CHECKS = 0;
...original mysqldump file contents...
set FOREIGN_KEY_CHECKS = 1;

Is there no way to automatically set those lines or export the tables in the necessary order (without having to manually specify all table names as that can be tedious and error prone)? I could wrap those lines in a script, but was wondering if there is an easy way to ensure I can dump a file and then import it without manually updating it.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysqldump