Skip to content

Instantly share code, notes, and snippets.

@egulhan
Created December 20, 2017 07:13
Show Gist options
  • Save egulhan/7974d8803551407286657b7504b1019b to your computer and use it in GitHub Desktop.
Save egulhan/7974d8803551407286657b7504b1019b to your computer and use it in GitHub Desktop.
Drop all MySQL database tables without foreign key checks
### connect mysql with -s and -r parameter to print "DROP TABLE ..." lines without formated
mysql -u -s -r
### run the following sql query to generate "DROP TABLE ..." queries
SELECT concat('DROP TABLE IF EXISTS ', table_name, ';')
FROM information_schema.tables
WHERE table_schema = '{DBNAME}';
### disable foreign key check
SET FOREIGN_KEY_CHECKS = 0;
### copy-paste your "DROP TABLE ..." sql queries
### enable foreign key check again
SET FOREIGN_KEY_CHECKS = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment