MySQL之使用truncate批量清空数据库表数据

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33733970/article/details/88822326

格式:

select CONCAT(‘truncate TABLE ‘,table_schema,’.’,TABLE_NAME, ‘;’) from INFORMATION_SCHEMA.TABLES where table_schema in (‘数据库1’,‘数据库2’);

直接把数据库名字替换下就可以了,得到结果形如:

±-----------------------------------------------------------+
| CONCAT(‘truncate TABLE ‘,table_schema,’.’,TABLE_NAME, ‘;’) |
±-----------------------------------------------------------+
| truncate TABLE dbname.ABOUTUSINFO; |
| truncate TABLE dbname.ABUTMENT; |
| truncate TABLE dbname.ABUTMENTFILE; |
| truncate TABLE dbname.ACHVORG; |
| truncate TABLE dbname.WORKFLOWNODE; |
| truncate TABLE dbname.ZONESERVICE; |
| truncate TABLE dbname.ZONESERVICEFILE; |
±-----------------------------------------------------------+
7 rows in set

把每条truncate语句前后的“|”替换为空字符
用文本编辑器(如 Notepad++)把每条truncate语句前后的“|”替换为空字符,方便后面一次复制多条执行;

复制truncate语句到mysql命令行执行,可以一次复制多条执行。

亲测,确实好用!不禁感叹:网友的智慧是无穷的!

参考文章:
https://blog.csdn.net/iw1210/article/details/79586033

猜你喜欢

转载自blog.csdn.net/qq_33733970/article/details/88822326