温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何使用Anemometer分析MySQL慢查询记录

发布时间:2022-01-14 15:56:37 来源:亿速云 阅读:133 作者:小新 栏目:数据库

这篇文章将为大家详细讲解有关如何使用Anemometer分析MySQL慢查询记录,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

  数据库管理员一般是用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慢查询记录”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI