共計 1782 個字符,預計需要花費 5 分鐘才能閱讀完成。
這篇文章將為大家詳細講解有關如何使用 Anemometer 分析 MySQL 慢查詢記錄,丸趣 TV 小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
數據庫管理員一般是用 percona 的 toolkit 工具來分析 MySQL 慢查詢記錄,但是不夠直觀。
下面介紹一款比較直觀的工具來統計分析 MySQL 慢查詢記錄 anemometer。
在使用之前需要安裝 percona 的 toolkit 工具,anemometer 提供 web 界面。
1. toolkit 安裝
# cd /data/www/my.xuebuyuan.com
# git clone https://github.com/box/Anemometer.git anemometer
# cd anemometer
2. 創建表和用戶名
mysql install.sql
mysql -e grant ALL ON slow_query_log.* to anemometer @ localhost IDENTIFIED BY my.xuebuyuan.com
mysql -e grant SELECT ON *.* to anemometer @ localhost IDENTIFIED BY my.xuebuyuan.com
3. 分析 MySQL 慢日志
# pt-query-digest –user=anemometer –password=superSecurePass \
–review D=slow_query_log,t=global_query_review \
–review-history D=slow_query_log,t=global_query_review_history \
–no-report –limit=0% –filter= \$event- {Bytes} = length(\$event- {arg}) and \$event- {hostname}=\ $HOSTNAME\ /data/log/mysql/slow.log
4. 配置 anemometer
# cp conf/sample.config.inc.php conf/config.inc.php
# vi conf/config.inc.php
$conf[datasources][localhost] = array(
host = localhost ,
port = 3306,
db = slow_query_log ,
user = anemometer ,
password = my.ttlsa.com ,
tables = array(
global_query_review = fact ,
global_query_review_history = dimension
),
source_type = slow_query_log
);
$conf[plugins] = array(
visual_explain = /usr/bin/pt-visual-explain ,
query_advisor = /usr/bin/pt-query-advisor ,
#… other lines
$conn[user] = anemometer
$conn[password] = my.ttlsa.com
return $conn;
},
5. 自動化處理
# vi /etc/logrotate.d/mysql
postrotate
pt-query-digest –user=anemometer –password=superSecurePass \
–review D=slow_query_log,t=global_query_review \
–review-history D=slow_query_log,t=global_query_review_history \
–no-report –limit=0% –filter= \$event- {Bytes} = length(\$event- {arg}) and \$event- {hostname}=\ $HOSTNAME\ /data/log/mysql/slow.log.1
endscript
這樣就可以通過 my.ttlsa.com/anemometer 來訪問查看慢查詢了。
關于“如何使用 Anemometer 分析 MySQL 慢查詢記錄”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。