[{"data":1,"prerenderedAt":107},["ShallowReactive",2],{"blog:\u002Fblog\u002F2016\u002F06\u002F18\u002Fmysql-batch-del\u002F":3},{"id":4,"title":5,"body":6,"categories":91,"comments":93,"date":94,"description":95,"draft":96,"extension":97,"legacySlug":98,"meta":99,"navigation":93,"path":100,"seo":101,"stem":102,"tags":103,"updated":105,"__hash__":106},"blog\u002Fblog\u002F2016\u002F06\u002F18\u002Fmysql-batch-del.md","批量删除mysql数据表",{"type":7,"value":8,"toc":82},"minimark",[9,13,17,20,31,34,48,51,67,70,78],[10,11,12],"h3",{"id":12},"问题描述",[14,15,16],"p",{},"​\t工作中我们会遇到批量删除一些mysql数据表的情况，比如现在有100个带'2012_'前缀的表，如何将其批量删除，it's a problem.",[10,18,19],{"id":19},"假设",[21,22,27],"pre",{"className":23,"code":25,"language":26},[24],"language-text","数据库：test\n表特征：'2012_'前缀\nmysql用户名：root\nmysql密码：passwd\n","text",[28,29,25],"code",{"__ignoreMap":30},"",[10,32,33],{"id":33},"解决方案",[21,35,39],{"className":36,"code":37,"language":38,"meta":30,"style":30},"language-shell shiki shiki-themes github-light github-dark","echo \"select concat('drop table ',  table_name ,';') from TABLES where TABLE_SCHEMA ='test' and table_name like '%2012\\_%' ;\" | mysql information_schema -uroot -ppasswd| sed -n '2,$p' | mysql test -uroot -ppasswd\n","shell",[28,40,41],{"__ignoreMap":30},[42,43,46],"span",{"class":44,"line":45},"line",1,[42,47,37],{},[10,49,50],{"id":50},"要点解析",[52,53,54,58,61,64],"ol",{},[55,56,57],"li",{},"上述命令应用了“管道”",[55,59,60],{},"'select concat'拼接出了查询语句",[55,62,63],{},"mysql中有一个默认存在的数据库information_schema，其中包含所有mysql的数据表信息",[55,65,66],{},"sed -n '2,$p'是取出管道输入的第二行到末尾行",[10,68,69],{"id":69},"注意事项",[52,71,72,75],{},[55,73,74],{},"如果你的环境变量中没有加入mysql的命令，把上述mysql命令替换为完整命令路径",[55,76,77],{},"数据无价，谨慎删除！😂",[79,80,81],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":30,"searchDepth":83,"depth":83,"links":84},2,[85,87,88,89,90],{"id":12,"depth":86,"text":12},3,{"id":19,"depth":86,"text":19},{"id":33,"depth":86,"text":33},{"id":50,"depth":86,"text":50},{"id":69,"depth":86,"text":69},[92],"Mysql",true,"2016-06-18 17:27:06","问题描述 ​ 工作中我们会遇到批量删除一些mysql数据表的情况，比如现在有100个带'2012'前缀的表，如何将其批量删除，it's a problem. 假设 数据库：test 表特征：'2012'前缀 mysql用户名：root mysql密码：passwd 解决方案 要点解析 1. 上述命令",false,"md","mysql-batch-del",{},"\u002Fblog\u002F2016\u002F06\u002F18\u002Fmysql-batch-del",{"title":5,"description":95},"blog\u002F2016\u002F06\u002F18\u002Fmysql-batch-del",[104],"mysql",null,"lBXzFx2-ucp4KCvBtVtaPOfqCJ8jpEjAnF-efNoi-qc",1783807996125]