干掉mysql连接线程的两种方法

方法1,通过sql命令执行,如下:

//查看所有连接的线程ID
show processlist;
//查找满足条件的连接,拼接kill语句
select concat('kill ',id,';') from  information_on_schema.processcesslist where Host like '10.13.42.106%';
//干掉相应的连接
kill 28001

方法2,通过mysqladmin命令行执行,如下:

#查询连接线程列表
./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306 processlist
#干掉相应的连接线程
./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306 kill 28001

./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306 kill `./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306 processlist| grep -i '192.168.33.31'| awk '{print $2}'` 
./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306  processlist | grep -i '192.168.33.31'

持续干掉192.168.33.31这台服务器到数据库的线程池连接:

#!/usr/bin/sh

KL="./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306 kill"

while : ;do
        for i in `./mysqladmin.exe -h 192.168.33.30 -uroot -p123456 --port=3306 processlist| grep -i '192.168.33.31'| awk '{print $2}'`;do
        echo "killing $i"
        $KL $i;
        done
done

你可能感兴趣的:(shell,mysql)