Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop multiple databases using mysql command

Tags:

mysql

I have many databases with different names. I want to drop multiple databases, Is there any command since all names of db are different.

Eg: mysql db, Test db, live db.

like image 763
Vinod HC Avatar asked Jan 11 '11 11:01

Vinod HC


1 Answers

As of I know, there is no specific command/query to delete multiple databases without having a specific pattern in their names. Even I was asked to do the favor several times. So I researched and found no specific solution. Then I tried the below hack. It worked without giving much trouble. May be it could help for you too.

Take all the databases using the below command.

SHOW DATABASES ;

Paste all of them in an excel/some other text file (I prefer NPP). Keep the only names which you want to delete from the list. Dont forget to remove your working db's from the list.

Add DROP DATABASE in front of those names.

That's it simple. Copy & Paste all of those in your workbench. You can execute all of them in one shot.

like image 196
Gowtham Vakani Avatar answered Sep 16 '22 11:09

Gowtham Vakani