MySQL Kill sleep进程_MySQL
程序员文章站
2022-06-15 22:29:48
...
有空再慢慢研究。。。
#!/bin/bash
#while [ "2" -gt "1" ]
#do
log_command=`mysqladmin processlist | grep -i sleep | wc -l`
date=`date +%Y%m%d/[%H:%M:%S]`
#echo $log_command
if [ "$log_command" -gt 250 ]
then
for i in `mysqladmin processlist | grep -i sleep | awk '{print $2}'`
do
mysqladmin kill $i
done
echo "$date : $log_command, sleep is too many i killed it" >> /data/killsleep/sleep.log
else
echo "$date : $log_command, not need to kill" >> /data/killsleep/sleep.log
fi
# sleep 180
#done
注意mysqladmin执行的用户,直接在命令行执行mysqladmin processlist | grep -i sleep | wc -l,实际上是-uroot。在命令行执行这个脚本时候用的是登录服务器的用户。而用crontab执行的时候,虽然编辑的是root的crontab,但执行的时候不是root用户,是哪个我也不知道。最好在crontab的命令里加上su - root。
--------------------------------------------------------------------------------------
#It is used to kill processlist of mysql sleep~~~
#!/bin/sh
while :
do
n=`/opt/mysql/bin/mysqladmin processlist|grep -i sleep |wc -l`
date=`date +%Y%m%d/[%H:%M:%S]`
echo $n
# id=`/opt/mysql/bin/mysqladmin processlist |grep Sleep |awk '{if ($12 > 100) {print $2}}'`
# echo "$date : $n" >> /tmp/sleep.log
# if [ id != "" ]
# then
# for j in $id
# do
# /opt/mysql/bin/mysqladmin kill $j
# echo "$date : sleep is to long " >> /tmp/sleep.log
# fi
#
if [ "$n" -gt 60 ]
then
for i in `/opt/mysql/bin/mysqladmin processlist|grep -i sleep |awk '{print $2}'`
do
/opt/mysql/bin/mysqladmin kill $i
done
echo "sleep is too many i killed it " >> /tmp/sleep.log
echo "$date : $n" >> /tmp/sleep.log
fi
sleep 1
done
--------------------------------------------------------
#!/bin/bash
#while [ "2" -gt "1" ]
#do
log_command=`mysqladmin processlist | grep -i sleep | wc -l`
date=`date +%Y%m%d/[%H:%M:%S]`
#echo $log_command
if [ "$log_command" -gt 250 ]
then
for i in `mysqladmin processlist | grep -i sleep | awk '{print $2}'`
do
mysqladmin kill $i
done
echo "$date : $log_command, sleep is too many i killed it" >> /data/killsleep/sleep.log
else
echo "$date : $log_command, not need to kill" >> /data/killsleep/sleep.log
fi
# sleep 180
#done
注意mysqladmin执行的用户,直接在命令行执行mysqladmin processlist | grep -i sleep | wc -l,实际上是-uroot。在命令行执行这个脚本时候用的是登录服务器的用户。而用crontab执行的时候,虽然编辑的是root的crontab,但执行的时候不是root用户,是哪个我也不知道。最好在crontab的命令里加上su - root。
--------------------------------------------------------------------------------------
#It is used to kill processlist of mysql sleep~~~
#!/bin/sh
while :
do
n=`/opt/mysql/bin/mysqladmin processlist|grep -i sleep |wc -l`
date=`date +%Y%m%d/[%H:%M:%S]`
echo $n
# id=`/opt/mysql/bin/mysqladmin processlist |grep Sleep |awk '{if ($12 > 100) {print $2}}'`
# echo "$date : $n" >> /tmp/sleep.log
# if [ id != "" ]
# then
# for j in $id
# do
# /opt/mysql/bin/mysqladmin kill $j
# echo "$date : sleep is to long " >> /tmp/sleep.log
# fi
#
if [ "$n" -gt 60 ]
then
for i in `/opt/mysql/bin/mysqladmin processlist|grep -i sleep |awk '{print $2}'`
do
/opt/mysql/bin/mysqladmin kill $i
done
echo "sleep is too many i killed it " >> /tmp/sleep.log
echo "$date : $n" >> /tmp/sleep.log
fi
sleep 1
done
推荐阅读
-
Mysql 本地计算机无法启动 mysql 服务 错误 1067:进程意外终止。
-
MySQL服务器进程CPU占用100%的解决方法
-
Mysql 本地计算机无法启动 mysql 服务 错误 1067:进程意外终止。
-
python基于mysql实现的简单队列以及跨进程锁实例详解
-
无法启动mysql服务”1067 进程意外终止”解决办法【简记】
-
[日常] PHP与Mysql测试kill慢查询并检验PDO的错误模式
-
Mysql使用kill命令解决死锁问题(杀死某条正在执行的sql语句)
-
python基于mysql实现的简单队列以及跨进程锁实例详解
-
mysql 线程等待时间,解决sleep进程过多的办法
-
mysql 线程等待时间,解决sleep进程过多的办法