zoukankan      html  css  js  c++  java
  • 批量 kill mysql 线程

    时常有一些烂sql跑在数据库里,我们要进行kill,避免影响拖垮数据库。

     

    mysql> show processlist;

    +----+------+---------------------+--------------------+---------+------+----------+------------------+
    | Id | User | Host | db | Command | Time | State | Info |
    +----+------+---------------------+--------------------+---------+------+----------+------------------+
    | 6 | root | 192.168.40.71:44018 | information_schema | Query | 0 | starting | show processlist |
    +----+------+---------------------+--------------------+---------+------+----------+------------------+
    1 row in set (0.00 sec)

    mysql> select * from processlist;
    +----+------+---------------------+--------------------+---------+------+-----------+---------------------------+
    | ID | USER | HOST | DB | COMMAND | TIME | STATE | INFO |
    +----+------+---------------------+--------------------+---------+------+-----------+---------------------------+
    | 6 | root | 192.168.40.71:44018 | information_schema | Query | 0 | executing | select * from processlist |
    +----+------+---------------------+--------------------+---------+------+-----------+---------------------------+
    1 row in set (0.00 sec)

    这两个命令本质是一样的。

    所以只要找到你符合你条件的线程id就可以kill了。

     

    mysql -uroot -S /tmp/mysql_20158.sock -sNe "select id from information_schema.processlist where COMMAND='Sleep' and TIME>60" | xargs -n 1 mysqladmin -uroot -S /tmp/mysql_20158.sock kill

    或者生成kill 命令,再自己手动执行:
    select concat('KILL ',id,';') from information_schema.processlist where COMMAND='Sleep' and TIME>60;


    或者用工具mt-kill pt-kill

    pt-kill --host=192.168.1.2 --user=root --password=000000 --port=3306 --busy-time 60 --match-command="query|Execute" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

    pt-kill --host=192.168.1.2 --user=root --password=000000 --port=3306 --busy-time 60 --match-state="Locked|Sending data" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

    pt-kill --host=192.168.1.2 --user=root --password=000000 --port=3306 --busy-time 60 --match-info="SELECT|DELETE" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

  • 相关阅读:
    java制作的applet小型播放器
    java文件路径问题及Eclipse package,source folder,folder区别及相互转换
    转:文件操作之File类使用
    JFrame setDefaultLookAndFeelDecorated(true)
    java错误Cannot make a static reference to the nonstatic method
    转:HTML操作 Swing Components
    组件服务简介
    计算ttest 的C程序
    Excel统计函数中比较常用的函数
    Correlation with pvalues
  • 原文地址:https://www.cnblogs.com/zejin2008/p/8601232.html
Copyright © 2011-2022 走看看