Created
November 16, 2015 23:44
-
-
Save aaemnnosttv/f567fe10b9e9e03f7d48 to your computer and use it in GitHub Desktop.
mysql: Drop all tables by prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET GROUP_CONCAT_MAX_LEN=10000; | |
SET FOREIGN_KEY_CHECKS = 0; | |
SET @tbls = (SELECT GROUP_CONCAT(CONCAT('`', TABLE_NAME, '`')) | |
FROM information_schema.TABLES | |
WHERE TABLE_SCHEMA = 'tablename_goes_here' | |
AND TABLE_NAME LIKE 'thetableprefix_%'); | |
SET @delStmt = CONCAT('DROP TABLE ', @tbls); | |
-- SELECT @delStmt; | |
PREPARE stmt FROM @delStmt; | |
EXECUTE stmt; | |
DEALLOCATE PREPARE stmt; | |
SET FOREIGN_KEY_CHECKS = 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment