mysql清除单一库内数据表

本文介绍了一种利用MySQL的information_schema库来批量生成并执行删除表命令的方法,有效解决了手动逐个删除大量表的繁琐工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

删除表的命令

drop table 表名;

如果有200张表,执行200次,想想就不想动手了。

下面提供一个使用information_schema库的方案:

SELECT GROUP_CONCAT(CONCAT('drop table ',table_name) separator ';') FROM information_schema.`TABLES` WHERE table_schema='db';



下面是实际操作

MySQL [seahub-db]> SELECT GROUP_CONCAT(CONCAT('drop table ',table_name) separator ';') FROM information_schema.`TABLES` WHERE table_schema='seahub-db';
+-------------------------------------------------------------------------------------------------------------------------------------+
| GROUP_CONCAT(CONCAT('drop table ',table_name) separator ';')                                                                       |
+-------------------------------------------------------------------------------------------------------------------------------------+
| drop table share_fileshare;drop table termsandconditions_termsandconditions;drop table two_factor_staticdevice;drop table wiki_wiki |
+-------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


###执行刚生成的drop语句
MySQL [seahub-db]> drop table share_fileshare;drop table termsandconditions_termsandconditions;drop table two_factor_staticdevice;drop table wiki_wiki;
Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.06 sec)

Query OK, 0 rows affected (0.08 sec)

MySQL [seahub-db]> show tables;
Empty set (0.00 sec)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值