mysql批量kill线程的实例代码

发布时间:2019-10-05编辑:脚本学堂
本文介绍下,在mysql数据库中,批量kill清理线程的方法,有需要的朋友参考下。

mysql中批量kill线程,代码如下:
 

复制代码 代码示例:

mysqladmin -uroot -p processlist|linuxjishu/13830.html target=_blank class=infotextkey>awk -F "|" '{if($3 == "username")print $2}'|xargs -n 1 mysqladmin -uroot -p kill

mysql> select concat('KILL ',id,';') from information_schema.processlist where user='root';
+------------------------+
| concat('KILL ',id,';') |
+------------------------+
| KILL 3101;             |
| KILL 2946;             |
+------------------------+
2 rows in set (0.00 sec)
 
mysql>select concat('KILL ',id,';') from information_schema.processlist where user='root' into outfile '/tmp/a.txt';
Query OK, 2 rows affected (0.00 sec)
 
mysql>source /tmp/a.txt;
Query OK, 0 rows affected (0.00 sec)