MySQL对比清除不必要的表

1. 将需要包含表查询并放到临时表中:show tables;

2. 使用下面SQL生成删除不必要表的SQL:

select concat('drop table if exists `', a.table_name, '`;')
from information_schema.tables a left join tmp.a tmp
on a.table_name = tmp.name
where a.table_schema = 'cook' and tmp.name is null

3. 执行2中生成的SQL

posted @ 2020-09-15 08:38  栖息之鹰  阅读(158)  评论(0编辑  收藏  举报