Our mysql processes can sometimes get backlogged and processes begin queuing up. I’d like to debug when and why this occurs by logging the processlist during slow times.
I’d like to run show full processlist; via a cron job and save output to text file if there are more than 50 rows returned.
Can you point me in the right direction?
For example:
echo "show full processlist;" | mysql -uroot > processlist-`date +%F-%H-%M`.log
I’d like to run that only when the result contains the text 50 rows in set (or greater than 50 rows).
First of all, make sure MySQL’s slow queries log isn’t what you need. Also, MySQL’s
-eparameter allows you to specify a query on the command line.Turning the logic around, this saves the process list and removes it when the process list isn’t long enough: