MySql怎么批量删除多个表
项目场景:
使用Navicat工具直接在界面中删除,只能单张表删除,不能多选
解决方案:
我们可以通过MySQL的语句来批量删除多个表,其中you_database替换成你要查询的数据库名字 delete_table改成你要删除匹配的数据表。
1.生成删除某个数据库下所有的表SQL
-- 查询构建批量删除表语句(根据数据库名称)
select concat('drop table ', TABLE_NAME, ';') from information_schema.TABLES
where TABLE_SCHEMA = 'you_database';
2.生成删除某个数据库下指定的表名SQL
-- 查询构建批量删除表语句(根据数据库中的表名称模糊查询)
select concat('drop table ', TABLE_NAME, ';') from information_schema.TABLES
where TABLE_SCHEMA = 'you_database' and TABLE_NAME like 'delete_table_%';
3.复制查出来的删除sql语句,并批量执行。
select concat('drop table ',table_name,';') from information_schema.tables where table_schema = 'rummy_log' and table_name like 'agent_game_bonus_flow_202111%';
drop table agent_game_bonus_flow_20211110;
drop table agent_game_bonus_flow_20211111;
drop table agent_game_bonus_flow_20211112;
drop table agent_game_bonus_flow_20211113;
drop table agent_game_bonus_flow_20211114;
drop table agent_game_bonus_flow_20211115;
drop table agent_game_bonus_flow_20211116;
drop table agent_game_bonus_flow_20211117;
drop table agent_game_bonus_flow_20211118;
drop table agent_game_bonus_flow_20211119;
drop table agent_game_bonus_flow_20211120;
drop table agent_game_bonus_flow_20211121;
drop table agent_game_bonus_flow_20211122;
drop table agent_game_bonus_flow_20211123;
drop table agent_game_bonus_flow_20211124;
drop table agent_game_bonus_flow_20211125;
drop table agent_game_bonus_flow_20211126;
drop table agent_game_bonus_flow_20211127;
drop table agent_game_bonus_flow_20211128;
drop table agent_game_bonus_flow_20211129;
drop table agent_game_bonus_flow_20211130;
如图:
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· .NET10 - 预览版1新功能体验(一)