MySQL:按前缀批量删除表格

2017-07-04 00:00:00 by 【6yang】, 106 visits, 收藏 | 返回

http://blog.csdn.net/iefreer/article/details/12627389

MySQL>drop table like "prefix_%"

mysql语法来组装,
 

SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' )   
AS statement FROM information_schema.tables   
WHERE table_schema = 'database_name' AND table_name LIKE 'myprefix_%';  


然后执行该组装后的命令,比如从slowquery表中删除掉所有tmp_开头的表:


SELECT CONCAT( 'DROP TABLE ', GROUP_CONCAT(table_name) , ';' ) AS statement FROM information_schema.tables WHERE table_schema = 'slowquery' AND table_name LIKE 'tmp_%';

复制出来,执行以后命令
drop table tmp_201301,tmp_201302,tmp_201351,tmp_201352;
分享到:
share

    图片原图

    loading

    loading