本文连接地址:http://blog.chinaunix.net/uid-31396856-id-5819025.html
DBA很多时间会遇到需要批量处理MySQL服务器的大量连接,比如查杀导致性能变坏的连接、查杀大量空连接、或者查杀大量错误查询,因为这些查询导致服务器不可用,严重的时候导致实例挂起。
我们通常有很多特殊的“脚本”,也有使用工具,可以将用户、源主机或者查询等作为参数参与执行操作,比如pt-kill。
还有一种方法可以通过几个命令使用MySQL来实现:
mysql> select concat('KILL ',id,';') from information_schema.processlist where user='calxxxx';
+------------------------+
| concat('KILL ',id,';') |
+------------------------+
| KILL 209444; |
| KILL 209867; |
+------------------------+
2 rows in set (0.11 sec)
mysql> select concat('KILL ',id,';') from information_schema.processlist where user='calxxxx' into outfile '/tmp/a.txt';
Query OK, 2 rows affected (0.00 sec)
[root@DisComputEngine_165_mysql ~]# cat /tmp/a.txt
KILL 209444;
KILL 209867;
mysql> source /tmp/a.txt;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
一般来说,这种方法比较强大。很多时候可以满足批量处理MySQL大量连接时候的一种处理手段,数据库上谨慎操作,请慎用,仅供参考
--The end!