Аватар пользователя Dima

MySQL: Dropping multiple databases at once, pure SQL query

Here is simple code to get executable SQL query to drop multiple databases at once:

  1. SELECT CONCAT('DROP DATABASE ', SCHEMA_NAME, ';')
  2. FROM `information_schema`.`SCHEMATA`
  3. WHERE SCHEMA_NAME LIKE 'cms_%';

Replace the cms_ prefix with yours, execute the query and and you will get the new SQL query with list of commands to drop multiple tables:

  1. DROP DATABASE cms_09_02;
  2. DROP DATABASE cms_09_10;
  3. DROP DATABASE cms_12_10;
  4. DROP DATABASE cms_13_10;
  5. DROP DATABASE cms_13_10_2;
  6. DROP DATABASE cms_13_10_3;
  7. DROP DATABASE cms_20_10_2014;
  8. DROP DATABASE cms_24_09;
  9. DROP DATABASE cms_live;
  10. DROP DATABASE cms_test;

Got from around the web.