MySQL連接線程kill利器之pt-kill

來源:互聯網
上載者:User

標籤:delete   使用者名稱   串連   creating   action   query   ssl   如何   ati   

如何每10秒檢查一次,殺死指定使用者超過100秒的查詢?

pt-kill --no-version-check --host 127.0.0.1 --port 3306 --user ‘xxxxxx‘ --password ‘xxxxxx‘ --charset utf8 --match-command Query --match-user 指定的使用者名稱 --busy-time 100 --kill --victims all --interval 10 --print

常用參數說明

    • no-version-check
      不最新檢查版本
    • host
      串連資料庫的地址
    • port
      串連資料庫的連接埠
    • user
      串連資料庫的使用者名稱
    • passowrd
      串連資料庫的密碼
    • charset
      指定字元集
    • match-command
      指定殺死的查詢類型
    • match-user
      指定殺死的使用者名稱,即殺死該使用者的查詢
    • busy-time
      指定殺死超過多少秒的查詢
    • kill
      執行kill命令
    • victims
      表示從匹配的結果中選擇,類似SQL中的where部分,all是全部的查詢
    • interal
      每隔多少秒檢查一次
    • print
      把kill的查詢列印出來

pt-kill 常用殺進程參數:

1. 按user kill

/usr/bin/pt-kill --busy-time 15   --match-user="dbUSER1 | dbUSER2,..." --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log  

註:測試通過按使用者來殺線程,注意--match-user多個使用者之間用 | 分隔。  

 

2. 按query來源 host kill

/usr/bin/pt-kill --busy-time 15   --match-host="192.168.10.10 | 192.168.10.11" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

使用 --ignore-host 或 --match-host  

註:測試通過按來源host來殺線程,注意--match-host多個host之間用 | 分隔。  

 

3. 按command kill

/usr/bin/pt-kill --busy-time 15   --match-command="query | Execute" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

/usr/bin/pt-kill --busy-time 15   --ignore-command="sleep | binlogdump" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

註:測試通過按command來殺掉線程,注意command的內容一定要嚴格匹配大小寫,否則會殺不掉。 注意--match-command多個command之間用 | 分隔,否則會失效。
(command有:Query、Sleep、Binlog Dump、Connect、Delayed insert、Execute、Fetch、Init DB、Kill、Prepare、Processlist、Quit、Reset stmt、Table Dump)

 

4. 按state kill

/usr/bin/pt-kill --busy-time 15 --match-state="Locked | Sending data" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

註:測試通過按state 來殺掉線程,注意state 的內容一定要嚴格匹配大小寫,否則會殺不掉。注意--match-state多個state之間用 | 分隔,否則會失效。

(state類型有:Locked、login、copy to tmp table、Copying to tmp table、Copying to tmp table on disk、Creating tmp table、executing、Reading from net、Sending data、Sorting for order、Sorting result、Table lock、Updating)

 

5. 按info關鍵字 kill

/usr/bin/pt-kill --busy-time 15 --match-info="SELECT | DELETE" --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log

註:測試通過按info來殺掉線程,注意info的內容一定要嚴格匹配大小寫,否則會殺不掉。注意--match-info多個info之間用 | 分隔,否則會失效。

--ignore-info    / --match-info
info可以使用select、update、insert、delete來進行匹配,並可使用"|"進行多項匹配,如"select|SELECT|delete|DELETE|update|UPDATE"

 

6. 按訪問的dbname kill

/usr/bin/pt-kill --busy-time 15 --match-db="db1 | db2"  --victim all --interval 1 --kill --daemonize --pid=/tmp/ptkill.pid --print --log=/home/pt-kill.log
 --ignore-db  / --match-db
註:測試通過按db來殺掉線程,注意db的內容一定要嚴格匹配大小寫,否則會殺不掉。注意--match-db多個db之間用 | 分隔,否則會失效。

 

另: Actions:
--kill                     殺掉串連並且退出
--kill-query           只殺掉串連執行的語句,但是線程不會被終止

 

具體請參考官網資料:https://www.percona.com/doc/percona-toolkit/2.1/pt-kill.html

 

MySQL連接線程kill利器之pt-kill

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.