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. [JAVA小项目]GUI界面的局域网聊天室

    思路: 1.服务端: 1.1 创建ServerSocket 监听本地端口 1.2 循环接收多个客户端的连接,并且把多个客户端连接的每个管道都为其创建线程. 服务端类的成员:链表--每个成员都是线程类- ...

  2. .NET开源工作流RoadFlow-表单设计-数据字典选择

    添加数字字典选择框: 选择范围:指定可选择的字典范围. 是否多选:指定是否可以多选.

  3. redis缓存技术在java中的应用

    https://blog.csdn.net/zhh1072773034/article/details/78538012

  4. 【java开发系列】—— JDOM创建、修改、删除、读取XML文件

    有很多中操作XML文件的方法,这里介绍一下JDOM的使用方法和技巧. JDOM下载地址 创建XML文档 XML文件是一种典型的树形文件,每个文档元素都是一个document元素的子节点.而每个子元素都 ...

  5. ZHS16GBK编码中汉字缺失

    生产中使用ZHS16GBK编码的Oracle数据库,若出现字,则会出现乱码 原因是此字不存在在ZHS16GBK编码中 解决方法可以:此二字结构相同,但是后面的在ZHS16GBK编码中出现

  6. RPMForge介绍及安装

    网站RPMForge介绍,安装 http://wiki.centos.org/AdditionalResources/Repositories/RPMForge#head-f0c3ecee3dbb40 ...

  7. 关于bootstrap-table服务端分页问题

    昨天项目中涉及到了前端表格分页问题.数据一共有1万多条,所以选择了后端分页. 之前用的都是前端分页,第一次使用后端分页.网上也找到了一些例子,最后做出来了. 这里用的是bootstrap-table插 ...

  8. 初学Pollard Rho算法

    前言 \(Pollard\ Rho\)是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:\(MillerRabin\)素数测试(关于\(MillerRabin\),可以参考这篇博客:初学Mi ...

  9. HDU 2082 普通型母函数

    分析: 组成单词好说,价值如何体现? 改变指数就行,例如: 这样,组成的单词,指数就是权值,多项式相乘,指数小于50的就OK: #include <bits/stdc++.h> using ...

  10. 超简单,快速修改Oracle10g的默认8080端口

    因为Oracle数据库默认的端口是8080,这也是tomcat服务器的默认端口. 为了避免端口冲突,我们通常会修改掉其中一个. 这里我们选择修改Oracle数据库的端口. 第一步:以管理员身份运行cm ...