Skip to content

Instantly share code, notes, and snippets.

@jibbius
Created May 16, 2013 15:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jibbius/5592685 to your computer and use it in GitHub Desktop.
Save jibbius/5592685 to your computer and use it in GitHub Desktop.
MySQL - Drop Tables WHERE tablename like();
/*
* MySQL - Drop Tables WHERE tablename like();
*/
SET @tables = NULL;
SELECT GROUP_CONCAT(table_schema, '.', table_name) INTO @tables FROM information_schema.tables
WHERE table_schema = 'db_1' AND
(
table_name LIKE BINARY 'wp_bp_%'
OR table_name LIKE BINARY 'wp_sam_%'
OR table_name LIKE BINARY 'wp_rg_%'
OR table_name LIKE BINARY 'wp_post%'
);
SET @tables = CONCAT('DROP TABLE ', @tables);
PREPARE stmt1 FROM @tables;
EXECUTE stmt1;
DEALLOCATE PREPARE stmt1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment