Created
August 18, 2013 18:18
-
-
Save kleinron/6263140 to your computer and use it in GitHub Desktop.
MySQL bulk drop table where table like... See the question and the answers: http://stackoverflow.com/q/11053116/17772
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 @temp_statement = NULL; | |
SELECT | |
GROUP_CONCAT(table_schema, '.`', table_name, '`') INTO @temp_statement | |
FROM | |
( | |
SELECT | |
table_schema, table_name | |
FROM | |
information_schema.tables | |
WHERE | |
table_schema = 'db_name_goes_here' AND table_name LIKE 'table_base_name_here_%' | |
LIMIT 10 -- a limit to avoid exceeding group_concat_max_len | |
) JUST_A_TEMP_NAME; | |
-- up to this point, @temp_statement holds something like this: | |
-- mydb.`table1`,mydb.`table2`,...,mydb.`tableN` | |
SET @temp_statement = CONCAT('DROP TABLE ', @temp_statement); | |
SELECT @temp_statement; -- let's see the SQL statement before executing it | |
PREPARE stmt1 FROM @temp_statement; | |
EXECUTE stmt1; | |
DEALLOCATE PREPARE stmt1; | |
SET @temp_statement = NULL; -- clean up |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment