優(yōu)化mysql――定時(shí)抓取processlist快照
有時(shí)開(kāi)啟了slow_log依然不能找到mysql的問(wèn)題所在,而又不能時(shí)刻在電腦前,來(lái)一個(gè)簡(jiǎn)單的cron,定時(shí)抓取processlist快照
本文引用地址:http://www.ex-cimer.com/article/201609/304764.htm例子中創(chuàng)建process權(quán)限的mysql用戶(hù)”mysqluser”,密碼”mysqlpwd”,當(dāng)show full processlist條數(shù)大于10時(shí)才會(huì)在路徑中顯示快照
創(chuàng)建文件cronprocesslist.sh,記得修改權(quán)限,不然無(wú)法執(zhí)行.
chmod 777 cronprocesslist.sh
#!/bin/bash
[ $(/usr/local/bin/mysql -umysqluser -pmysqlpwd -h mysqlhost -e show full processlist | tee /pathto/plist-`date +%F-%H-%M-%S`.log | wc -l) -lt 10 ] rm /pathto/plist-`date +%F-%H-%M-%S`.log
cron中添加
*/1 * * * * /path/cronprocesslist.sh
評(píng)論