mysql如何批量删除指定前缀的表

mysql没有现成的工具可以实现批量删除相同前缀的表,所以我们可以通过构造语句来进行删除;

首先通过以下语句构造出要执行的删除语句

SELECT CONCAT( 'drop table ', table_name, ';' ) 
FROM information_schema.tables 
WHERE table_name LIKE 'ot_%';

屏幕截图 2022-02-22 224239.png
CONCAT( 'drop table ', table_name, ';' )
drop table ot_ad;
drop table ot_banner;
drop table ot_collhistory;
drop table ot_collitem;
drop table ot_collresult;
drop table ot_colltype;
drop table ot_dbbak;
drop table ot_dberr;
drop table ot_filedata;
drop table ot_filever;
drop table ot_info;
drop table ot_infocontent1;
drop table ot_infomessage;
drop table ot_infomove;
drop table ot_infosys;
drop table ot_infotype;
drop table ot_infoweb;
drop table ot_keyword;
drop table ot_makediy;
drop table ot_member;
drop table ot_membergroup;
drop table ot_memberlog;
drop table ot_memberonline;
drop table ot_menufile;
drop table ot_menutree;
drop table ot_message;
drop table ot_paysoft;
drop table ot_sysadmin;
drop table ot_sysimages;
drop table ot_system;
drop table ot_template;
drop table ot_tplsys;
drop table ot_type;
drop table ot_upfile;
drop table ot_userapi;
drop table ot_userfile;
drop table ot_usergroup;
drop table ot_userip;
drop table ot_userlevel;
drop table ot_useronline;
drop table ot_users;
drop table ot_userscore;
drop table ot_usersys;
屏幕截图 2022-02-22 224314.png

然后复制该结果将该结果放入sql的可视化工具执行即可
发表评论 / Comment

提示:本文章评论功能已关闭