杀掉MYSQL死锁进程

vi /usr/local/killmysqlprocess.sh

#!/bin/bash
#*/1 * * * * /usr/local/src/killmysqlprocess.sh
backdir="/usr/local/logs/"
logfile="cms_mysql_killprocess_$(date +"%Y%m%d").log"
mysqlbindir="/usr/local/mysql/bin/"
#use commond 'vmstat' get proc num
vmstat > vmstat.tmp
pronum=`awk -F" " '{if (NR==3) print $1}' vmstat.tmp`
rm -f vmstat.tmp
#if pronum less 20, nothing to do.......... exit
if [ $pronum -lt 20 ]; then 
  exit
fi
#it's here more than 20,run kill mysql Lock process
${mysqlbindir}mysql -e "show full processlist" > processlist.tmp
#get Lock mysql process id
awk -F" " '/Locked/{print $1}' processlist.tmp >looplock.tmp
sleep 5
for line in `cat looplock.tmp`
do
  /usr/local/mysql/bin/mysql -e "kill ${line}"
done
rm -f looplock.tmp
#write kill log
echo $(date +"%Y-%m-%d %H:%M:%S") >> ${backdir}${logfile}
cat processlist.tmp >> ${backdir}${logfile}
rm -f processlist.tmp

 

chmod 777 killmysqlprocess.sh


/usr/local/killmysqlprocess.sh

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值