我如何才能登录" SHOW PROCESSLIST"当有N多的查询? [英] How can I log "show processlist" when there are more than n queries?

查看:125
本文介绍了我如何才能登录" SHOW PROCESSLIST"当有N多的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的MySQL进程可有时候会积压和流程开始排队。我想会出现这种情况通过在缓慢的时代记录ProcessList中调试时和

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.

我想运行显示全PROCESSLIST; 通过cron作业,并保存输出到文本文件,如果有超过 50 行返回。

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?

例如:

echo "show full processlist;" | mysql -uroot > processlist-`date +%F-%H-%M`.log

我想运行,只有当结果包含设置文本 50行(或大于 50 行)。

推荐答案

首先,确保MySQL的慢查询日志是不是你所需要的。此外,MySQL的 -e 参数允许你指定命令行上的查询。

First of all, make sure MySQL's slow queries log isn't what you need. Also, MySQL's -e parameter 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:

date=$(date +...) # set the desired date format here
[ $(mysql -uroot -e "show full processlist" | tee plist-$date.log | wc -l) -lt 51 ] && rm plist-$date.log

这篇关于我如何才能登录" SHOW PROCESSLIST"当有N多的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆