溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何使用Anemometer分析MySQL慢查詢記錄

發(fā)布時間:2022-01-14 15:56:37 來源:億速云 閱讀:144 作者:小新 欄目:數(shù)據(jù)庫

這篇文章將為大家詳細(xì)講解有關(guān)如何使用Anemometer分析MySQL慢查詢記錄,小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

  數(shù)據(jù)庫管理員一般是用percona的toolkit工具來分析MySQL慢查詢記錄,但是不夠直觀。

  下面介紹一款比較直觀的工具來統(tǒng)計(jì)分析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. 創(chuàng)建表和用戶名

  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來訪問查看慢查詢了。

關(guān)于“如何使用Anemometer分析MySQL慢查詢記錄”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)
AI