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您也可以想讀 |




































