Preface
 
    Sometimes,we are determined to kill some MySQL connections which are occupying huge resources(CPU,memory,etc) that maybe lead to server crash.Even though it's simple to use "kill id;"(id is a number of MySQL thread which we can get from "show processlist;") command of MySQL doing that kind of job.But it's not enough in function.
 
Introduce
 
    pt-kill is a commonly used tool in killing MySQL connections.It provides more individual functions by set different options than MySQL kill command.You can also use it to print the candidates to be killed instead of really killing them.Let's see some details of the tool below.
 
Procedure
 
Usage
 pt-kill [OPTIONS] [DSN]
Common parameters
 --busy-time -- Match queries that running longer than this time which match the "Command=Query" status.
--idle-time -- Match querries that idle/sleeping longer than this time which match the "Command=Sleep" status.
--victims -- Specify the scope which can be killed(default "oldest",others "all","all-but-oldest").
--match-user -- Specify a user which you want to match.
--match-host -- Specify a host which you want to match.
--match-db -- Specify a db which you want to match.
--match-command -- Specify a command type which you want to match.
--match-state -- Specify a state type which you want to match.
--match-info -- Specify a query which you want to match.
--test-matching -- Only used to match queries in file which contains the snapshot of processlist.(disable --run-time,--interval and --[no]ignore_self)
--run-time -- Specify the max running time(default unit is second).
--interval -- Specify the frequency for queries(default 30s if not set --interval).
--kill -- Execute a real kill command for those matched queries to kill both connections and queries.
--kill-query -- Do like what --kill does but merely queries,it does not kill connections.
--kill-busy-command -- It is usually used to kill the execute statement instead of query statement(eg.--kil-busy-command=execute).
--print -- Just print a kill statement instead of really execute them for matched queries.
--query-count -- Match query class if it has reached this value.

Demonstrate of mutually exclusive options.
Specify at least one of --kill, --kill-query, --print, --execute-command or --stop.
--any-busy-time & --each-busy-time.--kill & --kill-query.
--daemonize & --test-matching.
1. Print all kill statement of query threads which have been run over 10s.
 pt-kill -h192.168.56. -P3306 -urepl --ask-pass --victims=all --busy-time= --print
2. Kill all the query threads which have been run over 10s.
 pt-kill -h192.168.56. -P3306 -urepl --ask-pass --victims=all --busy-time= --kill
3. Kill all the query threads which have been run over 10s in every 60s.
 pt-kill -h192.168.56. -P3306 -urepl --ask-pass --victims=all --busy-time= --interval= --kill
4. Kill all the execute threads which have been run over 10s.
 pt-kill -h192.168.56. -P3306 -urepl --ask-pass --victims=all --busy-time= --match-command=execute --kill
5. Print all the query threads which have been run over 10s in processlist.
 mysql -e "show processlist;" > proclist.log
pt-kill --test-matching=proclist.log --busy-time= --print
Summary
  • pt-kill is a quite useful tool to fast and simply kill threads of MySQL.
  • It's a good behaviour using "--print" before you really execute killing operation.
  • By default,the replication thread will not be killed except for using "--replication-threads" option.
  • Notice,don't be confused with "--run-time" & "--busy-time",they're totally different.
 

Percona-Tookit工具包之pt-kill的更多相关文章

  1. Mysql: pt-table-checksum 和 pt-table-sync 检查主从一致性,实验过程

    一.安装 percona 包 1.安装仓库的包 https://www.percona.com/doc/percona-repo-config/yum-repo.html sudo yum insta ...

  2. Linux后台开发工具箱

    https://files-cdn.cnblogs.com/files/aquester/Linux后台开发工具箱.pdf 目录 目录 1 1. 前言 3 2. 脚本类工具 3 2.1. sed命令- ...

  3. Linux后台开发工具箱-葵花宝典

    Linux后台开发工具箱-葵花宝典 一见 2016/11/4 目录 目录 1 1. 前言 4 2. 脚本类工具 4 2.1. 双引号和单引号 4 2.2. 取脚本完整文件路径 5 2.3. 环境变量和 ...

  4. 推荐几款MySQL相关工具

    前言: 随着互联网技术的不断发展, MySQL 相关生态也越来越完善,越来越多的工具涌现出来.一些公司或个人纷纷开源出一些不错的工具,本篇文章主要介绍几款 MySQL 相关实用工具.提醒下,这里并不介 ...

  5. [知识库分享系列] 二、.NET(ASP.NET)

    最近时间又有了新的想法,当我用新的眼光在整理一些很老的知识库时,发现很多东西都已经过时,或者是很基础很零碎的知识点.如果分享出去大家不看倒好,更担心的是会误人子弟,但为了保证此系列的完整,还是选择分享 ...

  6. .OCX、.dll文件注册命令Regsvr32的使用

    1.打开文件,打开需要注册的OCX文件或dll文件,2.然后根据需要进行OCX文件或DLL文件的注册和反注册 DLL.OCX注册方法--文件Regsvr32用法及情况介绍 使用过activex的人都知 ...

  7. regsvr32 命令小集注册OCX控件,注册控件(包括十几个举例)

    Regsvr32 进程文件: regsvr32 or regsvr32.exe  进程名称: Microsoft DLL Registration Service  英文描述: regsvr32.ex ...

  8. SQL慢查询安装过程

    SQL慢查询 基本操作 打开防火墙 firewall-cmd --zone=public --add-port=3306/tcp --permanent firewall-cmd --reload 安 ...

  9. regsvr32.exe是什么东西

    Regsvr32命令修复系统故障实例使用过activex的人都知道,activex不注册是不能够被系统识别和使用的,一般安装程序都会自动地把它所使用的activex控件注册,但如果你拿到的一个控件需要 ...

  10. 快速安装Percona pt工具

    yum install perl-DBI perl-DBD-MySQL perl-Time-HiRes perl-Time-HiRes perl-IO-Socket-SSLwget http://pk ...

随机推荐

  1. cf1072D. Minimum path(BFS)

    题意 题目链接 给出一个\(n \times n\)的矩阵,允许修改\(k\)次,求一条从\((1, 1)\)到\((n, n)\)的路径.要求字典序最小 Sol 很显然的一个思路是对于每个点,预处理 ...

  2. react里面stateless函数的默认参数

    function fn({  children,  params,  dispatch,  location}) { }

  3. webAudioAPI

  4. 深入理解Javascript之执行上下文(Execution Context)

    在这篇文章中,将比较深入地阐述下执行上下文 - Javascript中最基础也是最重要的一个概念.相信读完这篇文章后,你就会明白javascript引擎内部在执行代码以前到底做了些什么,为什么某些函数 ...

  5. CNN 和RNN 中input 长度不一致问题

    转自:https://www.jianshu.com/p/86d667ee3c62,感谢分享! pad_sequences & Masking layer 上面提到,文本数据也可以用CNN来处 ...

  6. ARM 中可用性集使用的注意事项

    Azure 目前有两种部署模型:经典部署模型 (ASM) 和资源管理器 (ARM).如果您之前使用过 ASM 模式下的可用性集,那么很可能在使用 ARM 模式下的可用性集时,会遇到一些问题或者疑惑.这 ...

  7. 在centos7中安装redis,并通过node.js操作redis

    引言 最近在学习node.js 连接redis的模块,所以尝试了一下在虚拟机中安装cent OS7,并安装redis,并使用node.js 操作redis.所以顺便做个笔记. 如有不对的地方,欢迎大家 ...

  8. 初见git和github

    一.我的github helloworld程序的地址:https://github.com/wyf1213/wyf-project1 二.git/github的相关介绍资料 1.github是什么   ...

  9. http中COOKIE和SESSION有什么区别?(转知乎)

    作者:知乎用户链接:https://www.zhihu.com/question/19786827/answer/28752144来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注 ...

  10. mobile easyui兼容实体数据(tree插件为例)

    ORM的实体类和数据库的类是一一对应的,如果有多级的嵌套循环json返回到前台为了方便展示可以使用mobile easyui,但是mobile easyui又需要特定的属性才可以,比如id,text, ...