Home  >  Article  >  Database  >  使用pt-kill根据一定的规则来kill连接的方法_MySQL

使用pt-kill根据一定的规则来kill连接的方法_MySQL

PHP中文网
PHP中文网Original
2016-05-27 13:44:301363browse

pt-kill 是一个优秀的kill MySQL连接的一个工具,是percona toolkit的一部分,在因为空闲连接较多导致超过最大连接数、某个有问题的sql导致mysql负载很高时,都需要将一些连接kill掉,这个工具主要就是这个用途。

参数

–busy-time

运行时间

–idle-time

空闲时间

–victims

所有匹配的连接,对应有最久的连接

–interval

间隔时间,默认30s,有点长,可以根据实际情况来调节

–print

打印出来kill掉的连接

–match-command

匹配当前连接的命令

Query
Sleep
Binlog Dump
Connect
Delayed insert
Execute
Fetch
Init DB
Kill
Prepare
Processlist
Quit
Reset stmt
Table Dump
–match-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
–match-info

使用正则表达式匹配符合的sql

–match-db –match-user –match-host

见名知意

常用用法

杀掉空闲链接

pt-kill –match-command Sleep –idle-time 5 –host –port –interval –print –kill –victims all

杀掉运行时间超过5s的链接

pt-kill –match-command Query –busy-time 5 –host –port –interval –print –kill –victims all

杀掉匹配某个规则的正在运行的sql

pt-kill –match-command Query –busy-time 5 –host –port –interval –print –kill –victims all –match-info

杀掉正在进行filesort的sql

pt-kill –match-command Query –match-state “Sorting result” busy-time 5 –host –port –interval 
–print –kill –victims all

杀掉正在Copying to tmp table的sql

pt-kill –match-command Query –match-state “Copying to tmp table” busy-time 5 –host –port –interval 
–print –kill –victims all

以上就是使用pt-kill根据一定的规则来kill连接的方法_MySQL的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn