开启慢查询日志
mysql> show variables like 'slow_query%';
+
| Variable_name | Value |
+
| slow_query_log | ON |
| slow_query_log_file | /var/lib/mysql/data3-slow.log |
+
2 rows in set
set global slow_query_log=1;
mysql> show variables like 'long_query_time%';
+
| Variable_name | Value |
+
| long_query_time | 10.000000 |
+
1 row in set (0.00 sec)
set global long_query_time=5;
慢查询输出
mysql> show variables like '%log_output%';
+
| Variable_name | Value |
+
| log_output | FILE |
+
1 row in set
set global log_output='TABLE';
select * from mysql.slow_log;
其它配置
mysql> show variables like 'log_queries_not_using_indexes';
+
| Variable_name | Value |
+
| log_queries_not_using_indexes | OFF |
+
1 row in set (0.00 sec)
mysql> set global log_queries_not_using_indexes=1;