#!/bin/sh
mysql --user=$1 --password=$2 -BNe "show tables" $3 | tr 'n' ',' | sed -e 's/,$//' | awk '{print "SET FOREIGN_KEY_CHECKS = 0;DROP TABLE IF EXISTS " $1 ";SET FOREIGN_KEY_CHECKS = 1;"}' | mysql --user=$1 --password=$2 $3
Save code above in a file, say, mysql-drop-tables. Then change the permission to excecuteable
chmod +x mysql-delete-tables
Then run it
mysql-drop-tables dbuser dbpassword dbname
Here’s fhe file if you’re too lazy to copy paste
http://dl.dropbox.com/u/112837/scripts/mysql-drop-tables