记录一下mysql批量杀死连接的几种方法:
##通过information_schema.processlist表中的连接信息生成需要处理掉的MySQL连接的语句临时文件,然后执行临时文件中生成的指令。
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)
##使用mysqladmin:
--kill所有连接
mysqladmin -uroot -p processlist|awk -F "|" '{print $2}'|xargs -n 1 mysqladmin -uroot -p kill
--kill指定用户连接eg:Tim
mysqladmin -uroot -p processlist|awk -F "|" '{if($3 == "Tim")print $2}'|xargs -n 1 mysqladmin -uroot -p kill ##通过SHEL脚本实现kill锁定的MySQL连接
for id in mysqladmin processlist|grep -i locked|awk '{print $1}'
do
mysqladmin kill ${id}
done
31 October 2011 Suzhou, China记录一下方便查找 (原创文章)