shell脚本:Kill掉MySQL中所有sleep的client线程
分享一个shell脚本,实现kill掉mysql中所有的sleep状态的client线程,有需要的朋友,可以参考研究下。
文件名称:killsleep.sh。
#It is used to kill processlist of mysql sleep
#!/bin/sh
while :
do
n=`mysqladmin processlist -uadmin -pxxxxx|grep -i sleep |wc -l`
date=`date +%Y%m%d\[%H:%M:%S]`
echo $n
if [ "$n" -gt 10 ]
then
for i in `mysqladmin processlist -uadmin -pxxxxxx|grep -i sleep |awk '{print $2}'`
do
mysqladmin -uadmin -pxxxx kill $i
done
echo "sleep is too many I killed it " >> /tmp/sleep.log
echo "$date : $n" >> /tmp/sleep.log
fi
sleep 1
done