MySql【超简单】清空部分表的数据

tech2026-06-14  1

一、通过数据库的information_schema.tables表查询出需要清空的表

查询db_name库中的所有表,如果有特定的表不需要清空 条件后面添加 not in (‘table1’,‘table2’)

select concat('truncate table ',table_name,';') from information_schema.tables where table_schema='db_name' and TABLE_TYPE = 'BASE TABLE'

二、拼接出清空表的sql

select concat('truncate table ',table_name,';') from information_schema.tables where TABLE_TYPE = 'BASE TABLE'

三、运行sql

全选结果 Ctrl + C 复制出来 全部运行就OK了

最新回复(0)