日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 运维知识 > 数据库 >内容正文

数据库

mysql 工具 08s01_Mysql管理必备工具Maatkit详解之十四(mk-kill)

發(fā)布時(shí)間:2025/3/8 数据库 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 mysql 工具 08s01_Mysql管理必备工具Maatkit详解之十四(mk-kill) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

mk-kill - 顧名思義,殺mysql線程。安裝方法查看這里。

在一個(gè)OLTP的生產(chǎn)環(huán)境,一般不會(huì)讓sql執(zhí)行過(guò)長(zhǎng)的時(shí)間,特別是myisam這樣表鎖的引擎,如果出現(xiàn)長(zhǎng)時(shí)間執(zhí)行的sql一般是誤操作,要不就是出現(xiàn)問(wèn)題了。

出現(xiàn)這種情況,一般是登錄mysql手工執(zhí)行kill操作,Maatkit現(xiàn)在提供了一個(gè)命令來(lái)執(zhí)行這個(gè)操作。例如:

殺掉超過(guò)60秒的sql:

mk-kill –busy-time 60 –kill

如果你想先不殺,先看看有哪些sql運(yùn)行超過(guò)60秒:

mk-kill –busy-time 60 –print

如果你想殺掉,同時(shí)輸出殺掉了哪些進(jìn)程:

mk-kill –busy-time 60 –print –kill

下面舉例說(shuō)明:

先模擬一個(gè)長(zhǎng)時(shí)間的sql

mysq> select count(*) from test where gid>2;

把長(zhǎng)時(shí)間的sql打印:

[root@mysql2 ~]# mk-kill --busy-time 5 --print -u -p -h

# 2009-12-29T10:26:34 KILL 499967 (Query 33 sec) select count(*) from test where gid>2

將這個(gè)sql殺掉并打印:

[root@mysql2 ~]# mk-kill --busy-time 5 --print -u -p -h --kill

# 2009-12-29T10:27:09 KILL 499967 (Query 68 sec) select count(*) from test where gid>2

在查看原來(lái)模擬的sql:

mysql> select count(*) from test where gid>2;

ERROR 1053 (08S01): Server shutdown in progress

利用mk-kill可以根據(jù)自己的需求殺掉影響系統(tǒng)運(yùn)行的sql,怎么用就需要看自己的實(shí)際情況了。下面給出它的幫助:

mk-kill --help

mk-kill kills, prints or executes another script for queries in MySQL that match

certain criteria. If FILE is not given, mk-kill executes SHOW PROCESSLIST on

MySQL to get queries. Else, mk-kill will get queries from FILE which should

contain the output of SHOW PROCESSLIST. If FILE is -, mk-kill reads from STDIN.

For more details, please use the --help option, or try 'perldoc

/usr/bin/mk-kill' for complete documentation.

Usage: /usr/bin/mk-kill [OPTION]... [FILE...]

Options:

--ask-pass Prompt for a password when connecting to MySQL

--charset -A Default character set

--config Read this comma-separated list of config files; if

specified, this must be the first option on the command

line

--daemonize Fork to the background and detach from the shell

--defaults-file -F Only read mysql options from the given file

--heartbeat Print information to STDOUT about what is being done

--help Show help and exit

--host -h Connect to host

--interval How often to check for queries to kill. Optional suffix

s=seconds, m=minutes, h=hours, d=days; if no suffix, s is

used.

--iterations How many times to iterate through the find-and-kill cycle

(default 1)

--log Print all output to this file when daemonized

--password -p Password to use when connecting

--pid Create the given PID file when daemonized

--port -P Port number to use for connection

--run-time How long to run before exiting. Optional suffix

s=seconds, m=minutes, h=hours, d=days; if no suffix, s is

used.

--set-vars Set these MySQL variables (default wait_timeout=10000)

--socket -S Socket file to use for connection

--user -u User for login if not current user

--version Show version and exit

--wait-after-kill Wait after killing a query, before looking for more to

kill. Optional suffix s=seconds, m=minutes, h=hours,

d=days; if no suffix, s is used.

--wait-before-kill Wait before killing a query. Optional suffix s=seconds,

m=minutes, h=hours, d=days; if no suffix, s is used.

Actions:

--execute-command Execute this command when a query matches

--kill Actually kill matching queries

--print Print a KILL statement for matching queries; does not

actually kill queries

Matches:

--busy-time Kill connections that have been running for longer than

this time. Optional suffix s=seconds, m=minutes, h=hours,

d=days; if no suffix, s is used.

--idle-time Kill connections that have been idle/sleeping for longer

than this time. Optional suffix s=seconds, m=minutes,

h=hours, d=days; if no suffix, s is used.

--ignore-command Ignore queries whose Command matches this Perl regex

(default Binlog.Dump)

--ignore-db Ignore queries whose db (database) matches this Perl regex

--ignore-host Ignore queries whose Host matches this Perl regex

--ignore-info Ignore queries whose Info (query) matches this Perl regex

--[no]ignore-self Don't kill mk-kill's own connection (default yes)

--ignore-state Ignore queries whose State matches this Perl regex

(default Locked)

--ignore-user Ignore queries whose user matches this Perl regex (default

system.user)

--match-command Kill only queries whose Command matches this Perl regex

--match-db Kill only queries whose db (database) matches this Perl

regex

--match-host Kill only queries whose Host matches this Perl regex

--match-info Kill only queries whose Info (query) matches this Perl

regex

--match-state Kill only queries whose State matches this Perl regex

--match-user Kill only queries whose User matches this Perl regex

--[no]only-oldest Only kill the single oldest query (default yes)

Rules:

Specify at least one of --kill, --print or --execute-command.

總結(jié)

以上是生活随笔為你收集整理的mysql 工具 08s01_Mysql管理必备工具Maatkit详解之十四(mk-kill)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。