Drop all tables in a MySQL Database

2008 February 16

echo DROP TABLE `echo 'SHOW TABLES;' | mysql -u USER -p DATABASE | tail -n +2 | sed -e 's/$/,/'` | sed -e 's/,$/;/'

will output the necessary DROP TABLE command. If you have a my.cnf file (in the current directory) you can run the DROP at the same time with:

echo DROP TABLE `echo 'SHOW TABLES;' | mysql --defaults-file=my.cnf | tail -n +2 | sed -e 's/$/,/'` | sed -e 's/,$/;/' | mysql --defaults-file=my.cnf

read more…

Advertisements

Comments are closed.

%d bloggers like this: