Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mmuruev/4597f7c23ef18ef87794211650b88b56 to your computer and use it in GitHub Desktop.
Save mmuruev/4597f7c23ef18ef87794211650b88b56 to your computer and use it in GitHub Desktop.
Script for remove in one command all tables in databases, by given template
SET GROUP_CONCAT_MAX_LEN=10000;
SET @del = (
SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(CONCAT('`' , TABLE_SCHEMA , '`.`',table_name,'`')) , ';' )
AS statement FROM information_schema.tables
WHERE
TABLE_SCHEMA LIKE 'MY_DB_PREFIX_%' /* Criteria for selection */
OR TABLES.TABLE_NAME LIKE 'MY_TABLE_PREFIX_%';
);
PREPARE stmt FROM @del;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment