Skip to content

Instantly share code, notes, and snippets.

@aaemnnosttv
Created November 16, 2015 23:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save aaemnnosttv/f567fe10b9e9e03f7d48 to your computer and use it in GitHub Desktop.
Save aaemnnosttv/f567fe10b9e9e03f7d48 to your computer and use it in GitHub Desktop.
mysql: Drop all tables by prefix
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