Is FOREIGN_KEY_CHECKS=0 persistent

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Stryks
Forum Regular
Posts: 746
Joined: Wed Jan 14, 2004 5:06 pm

Is FOREIGN_KEY_CHECKS=0 persistent

Post by Stryks »

I know this might seem a strange question, but is setting FOREIGN_KEY_CHECKS=0 making a change to the database that will remain set until it gets set back to 1.

I ask because I notice that mysqldump automagically sets FOREIGN_KEY_CHECKS=0 at the start of the resulting SQL, which is great for importing because I don't have to worry about table restore order, etc.

However, it doesn't set it back to 1 afterwards, which I assume means that foreign key checks aren't resumed after the restore, leaving me to have to remember to turn it back on.

Might be missing something though. Any insights on this?

Cheers
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

I believe setting anything is done on a connection by connection basis. So if you run the query from the mysql dump, then with the same connection that value will still be set to 0. However, if you disconnect and then reconnect, it will reset to the value set in the mysql configuration.
Post Reply