Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing a single query from appearing in slow query log

Is a way to prevent a single query from appearing in mysql slow query log?

One may actually disable logging before executing the query (by setting a global variable) and enable it back after the query, but this would prevent logging in other threads as well, which is not desirable.

Do you have any ideas?

like image 719
Dmitry Granovsky Avatar asked Nov 09 '11 06:11

Dmitry Granovsky


People also ask

How do I turn off slow query log?

When you are done troubleshooting, disable the slow query log. To do this, run the mysql program again, and then type the following command: Copy SET GLOBAL slow_query_log = 'OFF'; You should only enable the slow query log for as long as it is necessary to troubleshoot performance issues.

Does slow query log affect performance?

It is safe to log slow queries with execution time bigger than a second without worry about performance impact in case of CPU-bound workload. The performance impact is negligibly small in IO-bound workload even if all queries are logged.

How do you slow a query log?

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. Set slow_query_log_file to specify the name of the log file.

Can I delete MySQL slow log?

You cannot delete the file, when mysql service is accessing the log file.


1 Answers

In MySQL 5.1 and later, you can make runtime changes to the time threshold for which queries are logged in the slow query log. Set it to something ridiculously high and the query is not likely to be logged.

SET SESSION long_query_time = 20000;
SELECT ...whatever...
SET SESSION long_query_time = 2;

Assuming 2 is the normal threshold you use.

like image 57
Bill Karwin Avatar answered Oct 18 '22 06:10

Bill Karwin