Skip to content

Instantly share code, notes, and snippets.

@iforwms
Created October 11, 2018 09:28
Show Gist options
  • Save iforwms/e1b16cd36684ff4b7a2267449526fa13 to your computer and use it in GitHub Desktop.
Save iforwms/e1b16cd36684ff4b7a2267449526fa13 to your computer and use it in GitHub Desktop.
Drop all SQL tables
mysqldump --add-drop-table --no-data -u root -p DB_NAME | grep 'DROP TABLE' > drop_all_tables.sql
mysql -u root -p DB_NAME < drop_all_tables.sql
===================
drop database DB_NAME;
===================
SET FOREIGN_KEY_CHECKS = 0;
SELECT
table_name
FROM
information_schema.tables
WHERE
table_schema = db_name;
And delete all tables on by one from the list:
DROP TABLE IF EXISTS table1;
DROP TABLE IF EXISTS table2;
DROP TABLE IF EXISTS table3;
Remember to turn on foreign key constraint after it’s done:
SET FOREIGN_KEY_CHECKS = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment