日期:2014-05-16  浏览次数:20946 次

mysql 慢日志查询操作
mysql慢日志查询步骤:


1.查询mysql版本
[root@user61 bin]# mysql -V
mysql  Ver 14.14 Distrib 5.1.54, for pc-linux-gnu (i686) using readline 5.1

2.检查当前服务器有没有在记录slow query:
mysql> show variables like 'log_%';
--------------------------------- --------------------------
| Variable_name                   | Value                    |
--------------------------------- --------------------------
| log_bin                         | OFF                      |
| log_bin_trust_function_creators | OFF                      |
| log_bin_trust_routine_creators  | OFF                      |
| log_error                       | /var/lib/mysql/error.log |
| log_output                      | FILE                     |
| log_queries_not_using_indexes   | ON                       |
| log_slave_updates               | OFF                      |
| log_slow_queries                | ON                       |
| log_warnings                    | 1                        |
--------------------------------- --------------------------

3.设置 log_slow_queries  为on:
SET global log_slow_queries=ON;

4.vi /etc/my.cnf增加如下内容: 
(注意对应目录的权限与db用户,
建议:
[root@user61 lib]# chown -R root:root mysql
[root@user61 lib]# chown -R 777 mysql
)

#log-slow-queries        = /var/lib/mysql/slow-queries.log
log-slow_queries        = /var/lib/mysql/slow-queries.log
long_query_time         = 3
log-queries-not-using-indexes
log-slow-admin-statements

log-error=/var/lib/mysql/error.log
log=/var/lib/mysql/mysql.log


5.slow-queries.log应该就有日志了


6.可以用( myprofi)     下载http://myprofi.sourceforge.net/
下载后就可直接用:php parser.php -slow /var/lib/mysql/slow-queries.log
可得结果
wget http://sourceforge.net/projects/nmon/files/nmon_linux_14g.tar.gz/download

7.与mysqlsla是时分析
wget http://cpan.perl.org/src/stable.tar.gz