Skip to content

Instantly share code, notes, and snippets.

@webarchitect609
Last active January 27, 2022 15:45
Show Gist options
  • Save webarchitect609/b3ad9d812f65855dccab612449d320c0 to your computer and use it in GitHub Desktop.
Save webarchitect609/b3ad9d812f65855dccab612449d320c0 to your computer and use it in GitHub Desktop.
Delete all the tables in MySQL database in one command
# 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