How to disable foreign key constraints in MySQL

Why would you want to disable a foreign key constraint? Well there are some scenarios... such as when you are refreshing your testing or development environment with production data or when you are restoring your production environment from a backup after an unfortunate mishap.

So how do you disable your constraints:

set foreign_key_checks=0;

Once you have done the necessary options, then you can re-enable them by running

set foreign_key_checks=1;

That's it.

Updated: 2020-07-15 | Posted: 2015-10-21