博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL连接线程kill利器之pt-kill
阅读量:6888 次
发布时间:2019-06-27

本文共 2988 字,大约阅读时间需要 9 分钟。

如何每10秒检查一次,杀死指定用户超过100秒的查询?

pt-kill \--no-version-check \--host 127.0.0.1 --port 3306 --user 'xxxxxx' --password 'xxxxxx' \--charset utf8 \--match-command Query \--match-user 指定的用户名 \--busy-time 100 \--kill \--victims all \--interval 10 \--print

常用参数说明

    • no-version-check
      不最新检查版本
    • host
      连接数据库的地址
    • port
      连接数据库的端口
    • user
      连接数据库的用户名
    • passowrd
      连接数据库的密码
    • charset
      指定字符集
    • match-command
      指定杀死的查询类型
    • match-user
      指定杀死的用户名,即杀死该用户的查询
    • busy-time
      指定杀死超过多少秒的查询
    • kill
      执行kill命令
    • victims
      表示从匹配的结果中选择,类似SQL中的where部分,all是全部的查询
    • interal
      每隔多少秒检查一次
    • print
      把kill的查询打印出来

pt-kill 常用杀进程参数:

1. 按user kill

/usr/bin/pt-kill --busy-time 15   --match-user="dbUSER1 | dbUSER2,..." --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log  

注:测试通过按用户来杀线程,注意--match-user多个用户之间用 | 分隔。  

 

2. 按query来源 host kill

/usr/bin/pt-kill --busy-time 15   --match-host="192.168.10.10 | 192.168.10.11" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

使用 --ignore-host 或 --match-host  

注:测试通过按来源host来杀线程,注意--match-host多个host之间用 | 分隔。  

 

3. 按command kill

/usr/bin/pt-kill --busy-time 15   --match-command="query | Execute" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

/usr/bin/pt-kill --busy-time 15   --ignore-command="sleep | binlogdump" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

注:测试通过按command来杀掉线程,注意command的内容一定要严格匹配大小写,否则会杀不掉。 注意--match-command多个command之间用 | 分隔,否则会失效。
(command有:Query、Sleep、Binlog Dump、Connect、Delayed insert、Execute、Fetch、Init DB、Kill、Prepare、Processlist、Quit、Reset stmt、Table Dump)

 

4. 按state kill

/usr/bin/pt-kill --busy-time 15 --match-state="Locked | Sending data" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

注:测试通过按state 来杀掉线程,注意state 的内容一定要严格匹配大小写,否则会杀不掉。注意--match-state多个state之间用 | 分隔,否则会失效。

(state类型有:Locked、login、copy to tmp table、Copying to tmp table、Copying to tmp table on disk、Creating tmp table、executing、Reading from net、Sending data、Sorting for order、Sorting result、Table lock、Updating)

 

5. 按info关键字 kill

/usr/bin/pt-kill --busy-time 15 --match-info="SELECT | DELETE" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

注:测试通过按info来杀掉线程,注意info的内容一定要严格匹配大小写,否则会杀不掉。注意--match-info多个info之间用 | 分隔,否则会失效。

--ignore-info    / --match-info

info可以使用select、update、insert、delete来进行匹配,并可使用"|"进行多项匹配,如"select|SELECT|delete|DELETE|update|UPDATE"

 

6. 按访问的dbname kill

/usr/bin/pt-kill --busy-time 15 --match-db="db1 | db2"  --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

 --ignore-db  / --match-db
注:测试通过按db来杀掉线程,注意db的内容一定要严格匹配大小写,否则会杀不掉。注意--match-db多个db之间用 | 分隔,否则会失效。

 

另: 关于Actions-----https://www.percona.com/doc/percona-toolkit/2.1/pt-kill.html#actions

--kill                     杀掉连接并且退出
--kill-query           只杀掉连接执行的语句,但是线程不会被终止

--print                 只打印出匹配的sql语句,不进行终止操作

 

具体请参考官网资料:https://www.percona.com/doc/percona-toolkit/2.1/pt-kill.html

 

转载地址:http://pgtbl.baihongyu.com/

你可能感兴趣的文章
软件工程第二章 习题2 第4题
查看>>
《JavaScript设计模式与开发实践》读书笔记之命令模式
查看>>
hdu Problem 1242 Rescue bfs + 优先队列
查看>>
HDU-1507-Uncle Tom's Inherited Land*
查看>>
force里面的射线检测
查看>>
oracle 12.1.0.2中对象锁对系统的较大影响
查看>>
tensorboard的使用
查看>>
java进程占用CPU资源过高分析脚本
查看>>
day17--JQuery实例
查看>>
0312-css样式(选择器、文本text、字体fonts、背景background)
查看>>
【BZOJ】4358: permu 莫队算法
查看>>
powerdesigner 遇到的各种问题总结
查看>>
(转)韦东山linux学习笔记——ubuntu 9.10 软件源问题
查看>>
SQL错误
查看>>
还款计算-复式记账
查看>>
C# 利用性能计数器监控网络状态
查看>>
网络对抗技术作业一
查看>>
最短路(Floyd_Warshall) POJ 2240 Arbitrage
查看>>
select2使用
查看>>
POJ1816:Wild Words——题解
查看>>