Created
December 8, 2021 12:05
-
-
Save hirnsturm/14e19a4c46b65d8b395e42ff39c5ad5f to your computer and use it in GitHub Desktop.
Drop all tables in MySQL with mysqldump
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
# | |
# 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