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. js异步流程控制-回调

    f1为耗时操作,f2依赖f1的数据,因此f2必须在f1之后执行: 个人理解是:将f2(回调函数)的代码放在异步函数内部的最后执行,相当于把同步操作的代码融合到异步函数内部的最后: let tag = ...

  2. webstorm上传vue代码至git

    Git在push时候,提示:push to origin/master was rejected 解决方案如下: 提交代码顺序 webstorm右键项目名称==>Git==>Commit ...

  3. ppt写作的注意事项

    PPT推荐字体及大小: 宋体严谨,适合正文,显示最清晰 黑体庄重,适合标题,或者强调区 隶书楷体,艺术性强,不适合投影 如果通过文字排版突出重点:加粗.加大字号.变色 PPT文字太多怎么办? 1.抽象 ...

  4. API 的历史

    原文出处: apievangelist   译文出处:灯下鼠 历史无处不在. 研究我们来自何方,有助于指引我们前行.科技的发展日新月异,但时常停一下匆忙的脚步,稍稍回顾一下历史,却总是有益的. 下面就 ...

  5. mybatis中sql语句查询操作

    动态sql where if where可以自动处理第一个and. <!-- 根据id查询用户信息 --> <!-- public User findUserById(int id) ...

  6. dedecms 去掉栏目页的预览功能

    首先找到include/typeunit.class.admin.php 再找到 ListAllType 方法,该方法的功能是“读出所有分类” 找到并将该方法内的所以以下代码注释或者删除”<a ...

  7. Python的免费在线学习课程

    网上资源不是本人的,所以,只是转发.其它的不负责 http://www.imooc.com/learn/177

  8. Python Day 15 递归、匿名函数、内置函数

    阅读目录 内容回顾 生成器的send方法 递归 匿名函数 内置函数 ##内容回顾 #1.带参装饰器 - 自定义 | wraps def wrap(info) def outer1(func): fro ...

  9. echarts图表与可视窗口的自适应

    由于要适应屏幕尺寸,发现了这个问题.网上搜到了两个办法,如下: 方法一: window.onresize = mychart.resize; 方法二: window.addEventListener( ...

  10. 2018.10.16 Java的IO与NIO

    IO流学习总结 一 Java IO,硬骨头也能变软 二 java IO体系的学习总结 三 Java IO面试题 NIO与AIO学习总结 一 Java NIO 概览 二 Java NIO 之 Buffe ...