zoukankan      html  css  js  c++  java
  • Percona-Tookit工具包之pt-kill

     
    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
    1 pt-kill [OPTIONS] [DSN]
    Common parameters
     1 --busy-time -- Match queries that running longer than this time which match the "Command=Query" status.
     2 --idle-time -- Match querries that idle/sleeping longer than this time which match the "Command=Sleep" status.
     3 --victims -- Specify the scope which can be killed(default "oldest",others "all","all-but-oldest").
     4 --match-user -- Specify a user which you want to match.
     5 --match-host -- Specify a host which you want to match.
     6 --match-db -- Specify a db which you want to match.
     7 --match-command -- Specify a command type which you want to match.
     8 --match-state -- Specify a state type which you want to match.
     9 --match-info -- Specify a query which you want to match.
    10 --test-matching -- Only used to match queries in file which contains the snapshot of processlist.(disable --run-time,--interval and --[no]ignore_self)
    11 --run-time -- Specify the max running time(default unit is second).
    12 --interval -- Specify the frequency for queries(default 30s if not set --interval).
    13 --kill -- Execute a real kill command for those matched queries to kill both connections and queries.
    14 --kill-query -- Do like what --kill does but merely queries,it does not kill connections.
    15 --kill-busy-command -- It is usually used to kill the execute statement instead of query statement(eg.--kil-busy-command=execute).
    16 --print -- Just print a kill statement instead of really execute them for matched queries.
    17 --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.
    1 pt-kill -h192.168.56.100 -P3306 -urepl --ask-pass --victims=all --busy-time=10 --print
    2. Kill all the query threads which have been run over 10s.
    1 pt-kill -h192.168.56.100 -P3306 -urepl --ask-pass --victims=all --busy-time=10 --kill
    3. Kill all the query threads which have been run over 10s in every 60s.
    1 pt-kill -h192.168.56.100 -P3306 -urepl --ask-pass --victims=all --busy-time=10 --interval=60 --kill
    4. Kill all the execute threads which have been run over 10s.
    1 pt-kill -h192.168.56.100 -P3306 -urepl --ask-pass --victims=all --busy-time=10 --match-command=execute --kill
    5. Print all the query threads which have been run over 10s in processlist.
    1 mysql -e "show processlist;" > proclist.log
    2 pt-kill --test-matching=proclist.log --busy-time=10 --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.
     
    版权声明:本文为博主原创文章,如需转载请保留此声明及博客链接,谢谢!
    博客地址: http://www.cnblogs.com/aaron8219 & http://blog.csdn.net/aaron8219
  • 相关阅读:
    电力企业信息化建设方案之调度信息报送系统
    HP QC IE11不支持( win7 64位 无法安装)解决方法
    ajax传递list集合
    mysql主从配置
    js动态获取地址栏后的参数
    html页面保存数的两种方式
    微信开发之八 页面获取周围beacon设备
    最好的时光在路上,最美的风景在远方
    【摄影】田子坊
    【前端统计图】echarts实现简单柱状图
  • 原文地址:https://www.cnblogs.com/aaron8219/p/9235771.html
Copyright © 2011-2022 走看看