Why all queries are going into slow query log in MySQL
Why all
queries are going into slow query log in MySQL
We got a problem that every query that we ran in MySQL database
got logged into slow query log even if the “Query_time” of that query is of sub seconds say 0.0034 whereas our
“long_query_time” is set to 8
seconds.
-- Reason we found out for this behavior:
After investigation we found out that the parameter “log_queries_not_using_indexes” was set
to ON and that is why all queries land into slow query log as they were not
using indexes. We turn it off and it solves our problem.
But if you do need logging of queries not using indexes then
please do turn it on.
set global log_queries_not_using_indexes=0;
set global log_queries_not_using_indexes=1;
or
set global log_queries_not_using_indexes=OFF;
set global log_queries_not_using_indexes=ON;
Remember it will not persist database restart, for that you have
to do parameter setting in my.cnf
Some of the
Parameters related to slow query log.
mysql> show global variables like '%slow%';
+---------------------+------------------------------+
| Variable_name |
Value |
+---------------------+------------------------------+
| slow_launch_time |
2 |
| slow_query_log |
ON |
| slow_query_log_file | /logmysql/log/mysql-slow.log |
+---------------------+------------------------------+
mysql> show global variables like '%indexes%';
+----------------------------------------+-------+
| Variable_name | Value |
+----------------------------------------+-------+
| log_queries_not_using_indexes | OFF |
| log_throttle_queries_not_using_indexes | 0 |
+----------------------------------------+-------+
mysql> show global variables like '%log_output%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_output |
FILE |
+---------------+-------+
mysql> show global variables like '%long%';
+--------------------------------------------------------+----------+
| Variable_name |
Value |
+--------------------------------------------------------+----------+
| long_query_time |
5.000000 |
+--------------------------------------------------------+----------+
How to
enable slow query in MySQL 5.6
[mysqld]
# Slow Query Log
slow-query-log=ON
slow_query_log_file=/logmysql/log/mysql-slow.log
long-query-time=5
log-output=FILE
Comments
Post a Comment