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

一、通过数据库的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'

MySql【超简单】清空部分表的数据_第1张图片

二、拼接出清空表的sql

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

MySql【超简单】清空部分表的数据_第2张图片

三、运行sql

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

你可能感兴趣的:(mysql)