首页 / 数据库 / MySQL / mysql dba系统学习(9)slow query log慢查询日志功能
mysql dba系统学习(9)slow query log慢查询日志功能2014-06-25慢查询日志(不包括获取锁的时间)1,开启慢查询日志功能以前的版本中开启慢查询日志功能的参数是--log_slow_queries在my.cnf文件中指定,但是现在新的版本中用参数--slow_query_log和--slow_query_log_file来指定slow_query_log=1slow_query_log_file=/tmp/mysqlslow.log重新启动mysqlmysql> show variables like "%slow%";+---------------------+--------------------+| Variable_name | Value |+---------------------+--------------------+| log_slow_queries | ON || slow_launch_time | 2 || slow_query_log | ON || slow_query_log_file | /tmp/mysqlslow.log |+---------------------+--------------------+4 rows in set (0.00 sec)2,慢查询相关的 参数long_query_time当查询超过long_query_time指定的时间,那么就会记录在慢查询日志文件中,默认是10秒mysql> show variables like "%long%";+--------------------+-----------+| Variable_name | Value |+--------------------+-----------+| long_query_time | 10.000000 |我们来吧时间调短试试,看看什么变化mysql> set session long_query_time=1; 调到1秒Query OK, 0 rows affected (0.00 sec)mysql> show variables like "%long%";+--------------------+----------+| Variable_name | Value |+--------------------+----------+| long_query_time | 1.000000 || max_long_data_size | 1048576 |+--------------------+----------+2 rows in set (0.00 sec)mysql> use test;Database changedmysql> create table t as select * from information_schema.tables;Query OK, 53 rows affected (0.12 sec)Records: 53 Duplicates: 0 Warnings: 0mysql> insert into t select * from t;Query OK, 3392 rows affected (0.11 sec)Records: 3392 Duplicates: 0 Warnings: 0这个时候达到了1秒钟了所以就要记录sql语句mysql> insert into t select * from t;^[[AQuery OK, 6784 rows affected (1.15 sec)Records: 6784 Duplicates: 0 Warnings: 0mysql> system more /tmp/mysqlslow.log/usr/local/mysql/libexec/mysqld, Version: 5.1.70-log (Source distribution). started with:Tcp port: 3306 Unix socket: /tmp/mysql.sockTime Id Command Argument# Time: 130903 18:46:28# User@Host: root[root] @ localhost []# Query_time: 1.150157 Lock_time: 0.000205 Rows_sent: 0 Rows_examined: 13568use test;SET timestamp=1378205188;insert into t select * from t;