MySQL — How to drop multiple tables when foreign keys are preventing that

Source: https://pixabay.com/en/database-schema-data-tables-schema-1895779/

This is a nice solution I found on StackOverFlow.com when I was looking for a way to remove some tables that had a lot of foreign keys — these keys were not allowing me to do the drop easily.

I have found it very useful, here it is with some minor improvements:

SET FOREIGN_KEY_CHECKS = 0; 
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables
FROM information_schema.tables
WHERE table_schema = 'your_db_name_here'; -- specify DB name here.
SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;