Page 1 of 1

Is FOREIGN_KEY_CHECKS=0 persistent

Posted: Mon Jul 23, 2007 8:01 pm
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

Posted: Tue Jul 24, 2007 10:47 am
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.