Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.