pt-kill
案例:
pt-kill --no-version-check -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --charset utf8 --match-command Query --match-info "(?i-xsm:^(select))|(.*sleep(61)*)" --match-user yonghuming --busy-time 10 --kill --victims all --interval 10 --print Enter MySQL password: # 2020-08-14T15:33:32 KILL 1475909 (Query 12 sec) select count(*),sleep(61) from t --busy-time 10 #查询超过10s就kill。 --interval 10 #每隔10s检测一次。 --victims all #杀掉所有匹配的。
--idle-time=3 sleep 3s
--busy-time=3 运行3s
--match-info "(?i-xsm:^(select))|(?i-xsm:^(update))|(?i-xsm:^(delete))"
--match-info ".*t.*where.*"
--ignore-user="root|repl"
--ignore-host='127.0.0.1'
—victims all 杀掉所有匹配的,oldest是kill掉最早的线程。
--match-db="open_db|xf_loupan_db"
--match-user="lc_rx|rc_ronly"
--match-host=‘192.168.100.%’ 多个host之间用 | 分隔
--daemonize --log='/root/kill.log' 后台记录日志
1、打印出sleep时间超过3秒的connection,仅仅打印,不kill
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --print --ignore-self --idle-time=3 --interval 2
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --print --ignore-self --idle-time=3 --interval 2 --run-time=10
2、打印query语句中带有sleep关键字(不区分大小写)的connection, 且Time超过3秒
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --print --ignore-self --interval 2 --match-info "(?i-xsm:(sleep))" --busy-time=3 --victims all
3、打印非系统用户的select开头,且执行时间超过3秒的 connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --print --interval 2 --match-info "(?i-xsm:^(select))" --ignore-user="root|repl" --kill --busy-time=3 --victims all
4、打印非系统用户的select,update,delete开头,且执行时间超过3秒的 connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --print --interval 2 --match-info "(?i-xsm:^(select))|(?i-xsm:^(update))|(?i-xsm:^(delete))" --ignore-user="root|repl" --busy-time=3 --kill --victims all
5、打印指定特征的query语句
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info ".*t.*where.*" --ignore-user="root|repl" --busy-time=3 --victims all
6、打印非系统库的select开头,且执行时间超过3秒的 connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info "(?i-xsm:^(select))" --ignore-db="mysql|information_schema" --ignore-user="root|repl" --busy-time=3 --victims all
7、打印非系统用户的select,update,delete开头,且执行时间超过3秒,且不是被locked住 的 connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info "(?i-xsm:^(select))|(?i-xsm:^(update))|(?i-xsm:^(delete))" --ignore-state="Locked" --ignore-user="root|repl" --busy-time=3 --victims all
8、打印非系统用户,指定state(Locked、login、Updating、Sorting for order等状态),且执行时间超过3秒 的 connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info "(?i-xsm:^(select))|(?i-xsm:^(update))|(?i-xsm:^(delete))" --match-state="Locked" --ignore-user="root|repl" --busy-time=3 --victims all
9、打印非系统用户,指定Command(Query、Sleep、Binlog Dump、Connect等状态),且执行时间超过3秒 的 connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info "(?i-xsm:^(select))|(?i-xsm:^(update))|(?i-xsm:^(delete))" --match-command="Connect" --ignore-user="root|repl" --busy-time=3 --victims all
10、打印 忽略指定来源host ip ,且select开头的,且执行时间超过3s的connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info ".*t.*where.*" --ignore-user="root|repl" --ignore-host='127.0.0.1' --busy-time=3 --victims all
11、kill掉非系统用户,Command=Sleep,且空闲时间为3s的connection
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-command="sleep" --ignore-user="root|repl" --busy-time=3 --victims all
12、打印非系统用户,指定特征的query,在后台运行,并打印日志
pt-kill -udball --ask-pass -S /tmp/mysqld.9001_mdowntest.sock --ignore-self --print --interval 2 --match-info ".*t.*where.*" --ignore-user="root|repl" --busy-time=3 --daemonize --log='/root/kill.log' --victims all
13、—match-command=”Query|Sleep” —victims oldest —busy-time=3
只kill最老的command为Query|Sleep的最老的链接
14、指定库
--match-db="open_db|xf_loupan_db"
15、指定用户的所有链接
--match-user="lc_rx|rc_ronly"