在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)