mysql连接池线程超过5分钟kill掉

环境

系统:centos7
mysql版本:5.6.29

#!/bin/bash
mysql_path="/opt/Service/mysql"
passwd=`cat /opt/Script/passwd_root`
mysql_user="root"
mysql_pid=` cat a.txt | awk '{print $1}'`
$mysql_path/bin/mysql -u$mysql_user -p$passwd  -e "show full processlist" | grep -i 'Query' > a.txt

query_time=`cat a.txt | awk '{print $6}'`
if [ $query_time -ge 300 ];then
    kill -9 $mysql_pid
else
    echo " query time $query_time "

fi

将连接池中状态为query的查询线程取出放在a.txt中,筛选出time,超过5分钟的kill掉该线程的ID号;


6547072-9d74aa01c3ff323d.png
例图.png

注:本脚本只在测试环境中测试过功能,但未在线上使用,需在线上使用,更具自身环境进行更改;

猜你喜欢

转载自blog.csdn.net/weixin_34383618/article/details/87558353