定时清理mysql sleep

Posted on 2021-10-09 13:02  黔人阿诺  阅读(203)  评论(0编辑  收藏  举报
#!/bin/sh
date=`date +%Y%m%d\[%H:%M:%S]`
n=`mysqladmin -uroot -p密码 processlist | grep -i sleep | wc -l`
echo "sleep count:$n"
if [ "$n" -gt 10 ]; 
then
 for i in `mysqladmin -uroot -p密码 processlist | grep -i sleep | awk '$12>1 {print $2}'`
 do
   mysqladmin -uroot -p密码 kill $i
 done
 echo "sleep is too many i killed it(time>0)." >> /www/killmysqlsleep.log
 echo "$date : $n" >> /www/killmysqlsleep.log 
fi