1、相关参数:
mysql> show variables like '%slow%';
+---------------------+---------------------------
| Variable_name | Value
+---------------------+---------------------------
| log_slow_queries | ON
| slow_launch_time | 2
| slow_query_log | ON
| slow_query_log_file | C:\Documents and Settings\
+---------------------+---------------------------
4 rows in set (0.00 sec)
2、设定
long_query_time=1;
mysql> show variables like '%long%';
+---------------------------------------------------+----------+
| Variable_name | Value |
+---------------------------------------------------+----------+
| long_query_time | 1.000000 |
| max_long_data_size | 1048576 |
| performance_schema_events_waits_history_long_size | 10000 |
+---------------------------------------------------+----------+
3 rows in set (0.00 sec)
记录位置:
mysql> show variables like 'log_output';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output | FILE |
+---------------+-------+
1 row in set (0.00 sec)
慢查询日志记录:
# Time: 131213 11:22:01
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 3.593750 Lock_time: 0.000000 Rows_sent: 131072 Rows_examined: 131072
use test;
SET timestamp=1386904921;
select * from test;
3、不使用索引的查询记录到slowlog中:
mysql> show variables like 'log_queries%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | OFF |
+-------------------------------+-------+
1 row in set (0.00 sec)
mysql> set log_queries_not_using_indexes=on;
ERROR 1229 (HY000): Variable 'log_queries_not_using_indexes' is a GLOBAL variable and should be set with SET GLOBAL
mysql> set gloabl log_queries_not_using_indexes=on;
ERROR 1193 (HY000): Unknown system variable 'gloabl'
mysql> set global log_queries_not_using_indexes=on;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'log_queries%';
+-------------------------------+-------+
| Variable_name | Value |
+-------------------------------+-------+
| log_queries_not_using_indexes | ON |
+-------------------------------+-------+
1 row in set (0.00 sec)
# Time: 131213 11:38:47
# User@Host: root[root] @ localhost [127.0.0.1]
# Query_time: 3.453125 Lock_time: 0.000000 Rows_sent: 131072 Rows_examined: 131072
SET timestamp=1386905927;
select * from test.test;
记录查过1秒并没有用索引的记录下来了!!!