Last active
January 27, 2022 15:45
-
-
Save webarchitect609/b3ad9d812f65855dccab612449d320c0 to your computer and use it in GitHub Desktop.
Delete all the tables in MySQL database in one command
This file contains 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
# WARNING!!! This is VERY DANGEROUS command! | |
# Deletes ALL TABLES in $DBNAME database QUICKLY and IRREVERSIBLY! | |
mysql -h $DBHOST -u $DBUSER $DBNAME -p \ | |
-BNe 'show tables' \ | |
| tr '\n' ',' \ | |
| sed -e 's#,$##' \ | |
| sed -e 'i\/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;' \ | |
-e 'i\DROP TABLE IF EXISTS ' \ | |
-e 'a\;' \ | |
-e 'a\/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;' \ | |
| tr -d '\n' \ | |
| mysql -h $DBHOST -u $DBUSER $DBNAME -p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment