Created
October 11, 2018 09:28
-
-
Save iforwms/e1b16cd36684ff4b7a2267449526fa13 to your computer and use it in GitHub Desktop.
Drop all SQL tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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