当前位置: 代码迷 >> MySQL >> mysql出现大量Sleep联接时,进行清理的脚本
  详细解决方案

mysql出现大量Sleep联接时,进行清理的脚本

热度:248   发布时间:2016-05-05 16:33:25.0
mysql出现大量Sleep连接时,进行清理的脚本
?
#! /bin/sh
#
# clear_sleep.sh
# Copyright (C) 2015 root <[email protected]>
#
# 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

?

  相关解决方案