Skip to content

Instantly share code, notes, and snippets.

@gwagroves
Last active October 10, 2019 14:38
Show Gist options
  • Save gwagroves/3fd1c8c2a342826671c0c17a42cd43b1 to your computer and use it in GitHub Desktop.
Save gwagroves/3fd1c8c2a342826671c0c17a42cd43b1 to your computer and use it in GitHub Desktop.
MySQL drop all tables from a database
# The following assumes credentials are saved in .my.cnf (or similar)
#
# Create a file with a drop table command for each table.
# (Replace "database" with the name of the database.)
#
mysqldump --add-drop-table --no-data database | grep 'DROP TABLE' > ~/little_bobby_tables.sql
# Check.
#
cat ~/little_bobby_tables.sql
# Run the commands.
#
mysql database < ~/little_bobby_tables.sql
# Remove that dangerous file!
#
rm ~/little_bobby_tables.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment