// mysql · logging & diagnostics

slow_query_log

Whether the slow query log is written.

默认
OFF
Range
ON, OFF
Restart needed
否
Default checked on
MySQL 8.4 LTS

作用

Logs statements slower than long_query_time to slow_query_log_file (or a table, depending on log_output).

默认值

OFF. OFF (MySQL 8.4).

Check the current value

SHOW GLOBAL VARIABLES LIKE 'slow_query_log';

SELECT VARIABLE_NAME, VARIABLE_SOURCE, MIN_VALUE, MAX_VALUE, SET_TIME
FROM performance_schema.variables_info
WHERE VARIABLE_NAME = 'slow_query_log';

Change it

SET GLOBAL slow_query_log = ON;    -- until the next restart
SET PERSIST slow_query_log = ON;   -- now and after restarts

No restart. SET GLOBAL or SET PERSIST takes effect immediately; SET PERSIST also writes mysqld-auto.cnf so the value survives restarts.

When to change it

Turn it on in production; analyze the file with mysqldumpslow or pt-query-digest.

What can go wrong

A low long_query_time on a busy server makes the log grow fast; rotate it.

Questions about slow_query_log

What is the default value of slow_query_log in MySQL?

OFF. OFF (MySQL 8.4).

Does changing slow_query_log require a restart?

No. No restart. SET GLOBAL or SET PERSIST takes effect immediately; SET PERSIST also writes mysqld-auto.cnf so the value survives restarts.

When should I change slow_query_log?

Turn it on in production; analyze the file with mysqldumpslow or pt-query-digest.

Back to all MySQL settings, or check the MySQL manual for every option.

// one client for every engine

Check slow_query_log on your own server

SQLly runs the query above against MySQL and the other engines in this reference, from one desktop app on macOS, Windows and Linux.