Drop all databases from mysql

Submit to reddit

Sometimes I need to clean a mysql server so I can re-import it clean from the backups. A DROP ALL DATABASES; would have been nice, but the following does the trick. It will drop all databases except for mysql, test and information_schema

1
mysql -uroot -pPASSĀ  -e "show databases" | grep -v Database | grep -v mysql| grep -v information_schema| grep -v test | gawk '{print "drop database " $1 ";"}' | mysql -uroot -pPASS</pre>

Warning:
It does what it says on the tin. It will DROP all your databases, no warnings, no confirmations!