在系统运行中,有时候突然出现N多的查询时间很长的连接,定位到问题后,需要清理掉,一个个KILL太繁琐,写了个脚本如下:
- #########################################################################
-
# #
-
# MySQL kill bad sql thread script #
-
# Writen by: Bruce #
-
# #
-
# Version: 1.5-r5 Released: 2011-05-25 #
-
# Licenced under GPLv2 #
-
# #
-
#########################################################################
-
#!/bin/bash
-
printf "Please enter Key Worlds:\n"
-
read Key
-
printf "Please enter your username:\n"
-
read Username
-
stty -echo
-
printf "Please enter your password:\n"
-
read Password
-
stty echo
-
for id in `mysql -u $Username -p$Password -e "show full processlist" | grep "$Key" | awk '{print $2}'`
-
do
-
mysqladmin -u$Username -p$Password kill ${id}
-
done
可以定义一个关键字,比如Locked的,或者查询语句中的某个表.
阅读(1482) | 评论(0) | 转发(0) |