【发布时间】:2015-10-31 03:33:45
【问题描述】:
好的,我有大约 68,000 个表需要删除一个特定的短语。当我运行命令时:
SHOW TABLES where table_name like '%phrase';
我得到了我需要的所有结果,但我尝试运行以下代码,它只摆脱了 68,000 个中的 6 个:
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
【问题讨论】: