Skip to content

Instantly share code, notes, and snippets.

@hirnsturm
Created December 8, 2021 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hirnsturm/14e19a4c46b65d8b395e42ff39c5ad5f to your computer and use it in GitHub Desktop.
Save hirnsturm/14e19a4c46b65d8b395e42ff39c5ad5f to your computer and use it in GitHub Desktop.
Drop all tables in MySQL with mysqldump
#
# Source: https://tableplus.com/blog/2018/08/mysql-how-to-drop-all-tables.html
#
# First, disable foreign key check:
echo "SET FOREIGN_KEY_CHECKS = 0;" > ./temp.sql
# Then dump the db with no data and drop all tables:
mysqldump --add-drop-table --no-data -u root -p db_name | grep 'DROP TABLE' >> ./temp.sql
# Turn the foreign key check back on:
echo "SET FOREIGN_KEY_CHECKS = 1;" >> ./temp.sql
# Now restore the db with the dump file:
mysql -u root -p db_name < ./temp.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment