Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL slow query log logging fast queries [closed]

I'm having an issue where MySQL seems to be logging queries in the slow query log that are faster than the time specified. I've configured MySQL to log the following:

Server version: 5.1.54-1ubuntu4-log

+---------------------+-------------------------------+
| Variable_name       | Value                         |
+---------------------+-------------------------------+
| log_slow_queries    | ON                            |
| long_query_time     | 2.000000                      |
| slow_query_log      | ON                            |
| slow_query_log_file | /var/log/mysql/mysql-slow.log |
+---------------------+-------------------------------+
4 rows in set (0.00 sec)

However, in my slow query log I can see that it's logging sub-second queries:

# Time: 121116 17:09:00
# User@Host: user[user] @ ip-10-x-x-x.ec2.internal [x.x.x.x]
# Query_time: 0.007098  Lock_time: 0.000075 Rows_sent: 50  Rows_examined: 2693

I've set the above variable dynamically using 'SET GLOBAL ...', but even before that the long_query_time was set to 1.000000 seconds.

Any idea why MySQL could be logging queries that are faster then what is specified?

like image 488
wrangler Avatar asked Nov 16 '12 17:11

wrangler


People also ask

Does slow query log affect performance?

Introduction. Slow queries can negatively impact database performance. If you don't analyze, optimize, and tune the slow queries as early as possible, the overall performance of your system will eventually degrade. Query optimization is essential to ensure high performance for the most important queries.

How do I disable slow query log in MySQL?

To disable or enable the slow query log or change the log file name at runtime, use the global slow_query_log and slow_query_log_file system variables. Set slow_query_log to 0 to disable the log or to 1 to enable it.

How do I find the slow query log path in MySQL?

By default, the slow query log file is located at /var/lib/mysql/hostname-slow. log.


1 Answers

According to the documentation, there's another option that could cause queries to get logged in the slow query log:

log_queries_not_using_indexes

like image 86
Ja͢ck Avatar answered Oct 13 '22 00:10

Ja͢ck