Dropping All MySQL Tables

Though there is no single command to drop all of the tables in a MySQL database, it is pretty easy to do with a simple script.

On my Linux environments, I run something like this:

#!/bin/bash

D_USER=username
D_PASS=password
D_HOST=localhost
D_DB=database

# dropping existing tables...
mysql -u$D_USER -p$D_PASS -h$D_HOST $D_DB -N -e \
"select concat('drop table if exists ', table_name, ' cascade;') from information_schema.tables where table_schema='$D_DB';" \
| mysql -u$D_USER -p$D_PASS -h$D_HOST $D_DB

The first part selects the drop table statement for each table; this is piped into a second invocation of mysql to run the commands.