Drop all tables in mysql without dropping database

Found this brilliant method of doing just that via nix command.
The reason why this is useful is that I generally don’t like to type every table name into the sql command.

mysqldump -u[USERNAME] -p[PASSWORD] --add-drop-table --no-data
[DATABASE] | grep ^DROP | mysql -u[USERNAME] -p[PASSWORD] [DATABASE]

3 thoughts on “Drop all tables in mysql without dropping database”

  1. Like this!

    I had also to delete a lot of other stuff besides tables, e.g. views, routines, triggers, events. I have changed the grep to

    "(^DROP|dddddsDROP|^USE)s"

    and it works now for all these other stuff too.

    Thanks for the idea!

Leave a Reply

Your email address will not be published.