Monitoring MySQL Queries Using Bash Script监测MySQL的查询使用的bash脚本
Monitoring MySQL queries is a favorite pastime of MySQL administrators especially for performance reasons.监测MySQL的疑问是一个最喜爱的消遣活动的MySQL管理员,尤其是出于性能原因。 Here is a simple bash script to monitor long running MySQL queries in realtime using the ubiquitous ’show processlist’.这里是一个简单的bash脚本,以监察长期运行MySQL查询在实时使用无处不在'显示processlist ' 。 The best part about this script is that you can use it to log your queries over time for later evaluation.最好的一部分,有关此脚本的是,您可以用它来记录您的疑问,随着时间的推移,后来的评价。
#!/bin/bash while [ 1 ] do mysql -N -u root -p password -e 'show processlist' |grep -v 'show processlist' sleep 2 done # ! / bin / bash比较,而[ 1 ]做的MySQL - N的中美根- p 密码娥'显示processlist ' | grep - V的'显示processlist '睡眠2做 Note: Replace password with your actual password.注:取代密码与您的实际密码。
Note: -N removes column headers.注: - N的删除栏标题。
This script excludes the show processlist thread itself.此脚本排除显示processlist线程本身。 You may also exclude the Sleeping threads with the following modification:您也可以排除沉睡的线程具有以下修改:
mysql -N -u root -p password -e ’show processlist’ | egrep -v ‘Sleep|show processlist’ MySQL的氮铀根- p 密码娥'显示processlist ' | egrep - V的'睡眠|显示processlist '
Note: This is not the only or best solution in market.注:这是不是唯一或最佳的解决办法是在市场。 There is mtop script with more functionality but written in perl.有mtop脚本与更多的功能,但写在Perl 。 I am alergic to perl and also couldn’t get it working in my only attempt.我alergic以Perl和也无法取得它的工作在我唯一的企图。 So here is a simple solution in bash.因此,这里是一个简单的解决办法的bash 。 Personally I don’t like hacking perl scripts.我个人不喜欢黑客Perl脚本。
Note: You can use slow query log too but in my experience a running top like display is better at finding bottlenecks.注意:您可以使用慢速查询日志太多,但在我的经验,正在运行的顶部一样,显示是在寻找更好的瓶颈。 Slow query log doesn’t indicate why a query took long time.慢速查询日志没有说明为什么查询了很长时间。 It could be because it was waiting on another query to complete.可以,因为它是在等待另一个查询完成。
Filed under提起下 Database数据库 , , Enterprise Software企业软件 , , Headline News头条新闻 , , How To如何 , , Linux Linux的 , , MySQL MySQL的 , , Open Source Software开放源码软件 , , Programming编程 , , RDBMS RDBMS的 , , Tech Note技术说明 , , Web网页 , , Web Hosting虚拟主机 , , Web Services Web服务 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article电子邮件此文章
You may also like to read您也可以想读 |



