日期:2014-05-16 浏览次数:20642 次
数据库偶尔会响应很慢,看着好像挂掉了,检查进程发现有大量查询语句把表锁住了,提供一个脚本给大家解决锁表导致的Mysql异常。
?
#!/bin/sh while : do n=`/usr/local/webserver/mysql/bin/mysql -uroot -p"kk41-,dnkkedkd8>/ee" -e 'show processlist;' | grep -i locked |grep -i search_keyword | wc -l` date=`date +%Y%m%d[%H:%M:%S]` echo $n if [ "$n" -gt 50 ] then for i in `/usr/local/webserver/mysql/bin/mysql -uroot -p"kk41-,dnkkedkd8>/ee" processlist | grep -i locked |grep -i search_keyword | awk '{print $2}'` do /usr/local/webserver/mysql/bin/mysql -uroot -p"kk41-,dnkkedkd8>/ee" kill $i done echo "killed it" >> /tmp/sleep.log echo "$date : $n" >> /tmp/sleep.log fi sleep 10 done?以上转自:http://www.604f.com/read.php?5