使用Anemometer分析MySQL慢查询记录
2017-02-10 11:33
225 查看
数据库管理员一般是用percona的toolkit工具来分析MySQL慢查询记录,但是不够直观。
下面介绍一款比较直观的工具来统计分析MySQL慢查询记录anemometer。
在使用之前需要安装percona的toolkit工具,anemometer提供web界面。
anemometer介绍参见:https://github.com/box/Anemometer/wiki
# git clone https://github.com/box/Anemometer.git anemometer
# cd anemometer
mysql -e "grant ALL ON slow_query_log.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
mysql -e "grant SELECT ON *.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
--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
# 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;
},
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来访问查看慢查询了。
参考文档:
https://www.box.com/blog/optimizing-mysql-performance-at-scale-with-anemometer-2/ http://isadba.com/?p=655
下面介绍一款比较直观的工具来统计分析MySQL慢查询记录anemometer。
在使用之前需要安装percona的toolkit工具,anemometer提供web界面。
anemometer介绍参见:https://github.com/box/Anemometer/wiki
1. 安装
# cd /data/www/my.ttlsa.com# git clone https://github.com/box/Anemometer.git anemometer
# cd anemometer
1 2 3 | # cd /data/www/my.ttlsa.com # git clone https://github.com/box/Anemometer.git anemometer # cd anemometer |
2. 创建表和用户名
mysql < install.sqlmysql -e "grant ALL ON slow_query_log.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
mysql -e "grant SELECT ON *.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';"
1 2 3 | mysql<install.sql mysql-e"grant ALL ON slow_query_log.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.com';" mysql-e"grant SELECT ON *.* to 'anemometer'@'localhost' IDENTIFIED BY 'my.ttlsa.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
1 2 3 4 | # pt-query-digest --user=anemometer --password=superSecurePass \ --reviewD=slow_query_log,t=global_query_review\ --review-historyD=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;
},
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | # 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/mysqlpostrotate
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
1 2 3 4 5 6 7 | # vi /etc/logrotate.d/mysql postrotate pt-query-digest--user=anemometer--password=superSecurePass\ --reviewD=slow_query_log,t=global_query_review\ --review-historyD=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 |
参考文档:
https://www.box.com/blog/optimizing-mysql-performance-at-scale-with-anemometer-2/ http://isadba.com/?p=655
相关文章推荐
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- mysql使用rand随机查询记录效率测试
- mysql使用rand随机查询记录效率测试
- 使用连接(JOIN)来代替子查询(Sub-Queries) mysql优化系列记录
- 使用mysql的disctinct group by查询不重复记录
- 使用mysql的disctinct group by查询不重复记录
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- mysql使用rand随机查询记录效率测试
- mysql使用rand随机查询记录效率测试
- mysql使用rand随机查询记录效率测试
- 使用 Mysql 做断点记录查询
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用mysqldumpslow和mysqlsla分析mysql慢查询日志
- mysql使用rand随机查询记录的高效率方法
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用distinct在mysql中查询多条不重复记录值的解决办法
- 使用distinct在mysql中查询多条不重复记录值