The Following command drops all databases in the mysql dbms except mysql, information_schema,test and OLD db’s.
The command is pretty handy when one needs to drop all the databases in one go:
What this does is
# mysql -uroot -p -e "show databases" | grep -v Database | grep -v mysql| grep -v information_schema| grep -v test | grep -v OLD |gawk '{print "drop database " $1 ";select sleep(0.1);"}' | mysql -uroot -ppassword
What this does is
- connect to a mysql dbms server and execute the command for showing all databases
- Omit lines that match “Database” while printing.
- Omit lines with mysql,infomation_schema and test.
- use gawk to print out the words “drop database” followed by the daabase name (which is in $1) and then a semicolon. Call sleep command.
- pipe all of above back to the mysql dbms to drop all those databases
Also,
mysql -uroot -pxxxxx -e "show databases" | grep -v Database | grep -v mysql | grep -v information_schema| grep -v test | grep -v OLD | gawk '{print "drop database " $1";select sleep(0.1);"}' > droppeddatabases.sql
0 comments:
Post a Comment