#! /bin/sh
#
# clear_sleep.sh
# Copyright (C) 2015 root <root@db01>
#
# Distributed under terms of the MIT license.
#
mysql -u root -p123456 -e "SET GLOBAL group_concat_max_len=102400;"
mysql -u root -p123456 -e "select
case count(1)>50
when true
then
(select group_concat(concat('KILL ',id,';') separator '') from information_schema.processlist where Command = 'Sleep' AND user = 'root' and host!='localhost')
else ''
end
from information_schema.processlist where Command = 'Sleep' AND user = 'root' and host!='localhost'
into outfile '/tmp/sleep_processes.txt'"
mysql -u root -p123456 -e "source /tmp/sleep_processes.txt;"
rm -rf /tmp/sleep_processes.txt
#
# clear_sleep.sh
# Copyright (C) 2015 root <root@db01>
#
# Distributed under terms of the MIT license.
#
mysql -u root -p123456 -e "SET GLOBAL group_concat_max_len=102400;"
mysql -u root -p123456 -e "select
case count(1)>50
when true
then
(select group_concat(concat('KILL ',id,';') separator '') from information_schema.processlist where Command = 'Sleep' AND user = 'root' and host!='localhost')
else ''
end
from information_schema.processlist where Command = 'Sleep' AND user = 'root' and host!='localhost'
into outfile '/tmp/sleep_processes.txt'"
mysql -u root -p123456 -e "source /tmp/sleep_processes.txt;"
rm -rf /tmp/sleep_processes.txt
本文介绍了一个用于清理MySQL中由root用户发起且Host非localhost的睡眠进程的Shell脚本。通过设置group_concat_max_len参数来确保可以获取到足够的信息,并利用information_schema.processlist表来查找符合条件的睡眠进程,然后将这些进程的ID收集起来并执行kill命令进行清理。
696

被折叠的 条评论
为什么被折叠?



