Drop MySql Databases Wich Dosnt Have Any Table

Drop MySql databases wich dosnt have any table

If you did a bulk import, or when you receive error in middle of importing large sql. mostly there will be empty schemas in mysql(maria too) so now you can select all tables’s distincts schema’s name. then remove all schemas with tables from all schemas. tada!

actually no one will need it but, every 2 week i found myself in typing this script. so i paste it here to for my next usages. ^^

select Concat('Drop SCHEMA ',x.SCHEMA_NAME,';') 
from `information_schema`.SCHEMATA as x
where x.schema_name not in ( SELECT DISTINCT(b.TABLE_SCHEMA) 
                               FROM `information_schema`.`TABLES` as b )

Bir cevap yazın

E-posta hesabınız yayımlanmayacak. Gerekli alanlar * ile işaretlenmişlerdir

This site uses Akismet to reduce spam. Learn how your comment data is processed.