Remove all foreign keys from MySQL database

By John C. Zastrow

I needed to load some lookup data into a MySQL database littered with foreign keys. So I copied the empty DB and ran the output of the following:

SELECT CONCAT('alter table ',table_schema,'.',table_name,' DROP FOREIGN KEY ',constraint_name,';')  
FROM information_schema.table_constraints  
WHERE constraint_type='FOREIGN KEY' AND table_schema = 'MY_DATABASE_NAME_HERE'; \

I loaded the values, and dumped just the values (only insert statements) that I will use to populate the version of the DB with my FK’s intact.