Background
Under certain circumstances you might want to trash all the databases you have on a server. This article explains how to do it. Please note that this is a dangerous function and should only be done when you really know what you’re doing.
How to drop all MySQL Tables
Issue the following command to drop all MySQL tables on a MySQL server, preserving the system tables called mysql
and information_schema
:
mysql -uroot -proot_password -e "show databases" | grep -v Database | grep -v mysql | grep -v information_schema | gawk '{print "drop database `" $1 "`;select sleep(0.1);"}' | mysql -uroot -proot_password
Please note the above command removes sys
and performance_schema
, so if you want those back, do this:
mysql_upgrade --force
Reference
https://stackoverflow.com/questions/22301635/drop-all-databases-in-mysql