Home  >  Article  >  Database  >  Mysql里面执行show processlist出现很多Sleep状态的线程_MySQL

Mysql里面执行show processlist出现很多Sleep状态的线程_MySQL

WBOY
WBOYOriginal
2016-06-01 13:31:332742browse

bitsCN.com

Mysql里面执行show processlist出现很多Sleep状态的线程

 

由于程序设计的Bug,导致目前这个项目使用的数据库中有很多Sleep状态的线程。找了很多解决办法,还没发现最终有效的解决方案。只能临时使用如下方法:

 

编写shell文件,如killSleepProcess.sh

 

[plain] while :  do    n=`mysqladmin -uroot -p*** processlist | grep -i sleep | wc -l`    date=`date +%Y%m%d/[%H:%M:%S]`    echo $n      if [ "$n" -gt 10 ]    then      for i in `mysqladmin -uroot -p*** processlist | grep -i sleep | awk '{print $2}'`      do        mysqladmin  -uroot -p*** kill $i      done      echo "sleep is too many i killed it" >> /root/tmp/sleep.log      echo "$date : $n" >> /root/tmp/sleep.log    fi  sleep 120 #每隔120 秒 执行一次  done  

 

上面shell代码的结果是:将show processlist查询出的所有为Sleep状态的线程kill掉

 

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn