Friday, November 18, 2011

Drop all tables in one command

Drop all tables in one shot:

mysql --user=xxxx --password=xxxx -BNe "show tables" database_name | tr '\n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " $1 ";SET FOREIGN_KEY_CHECKS = 1;"}' | mysql --user=xxxx --password=xxxx database_name