// mysql · logging & diagnostics

long_query_time

Seconds a statement must run to be written to the slow query log.

默认
10
Range
0 to 31536000 seconds, with microsecond resolution
Restart needed
否
Default checked on
MySQL 8.4 LTS

作用

Fractional values work down to microseconds. The time excludes waiting for table locks.

默认值

10. 10 seconds (MySQL 8.4).

Check the current value

SHOW GLOBAL VARIABLES LIKE 'long_query_time';

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

Change it

SET SESSION long_query_time = 0.5;   -- this connection
SET GLOBAL long_query_time = 0.5;    -- new connections, until restart
SET PERSIST long_query_time = 0.5;   -- new connections, and after restarts

No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.

When to change it

10 seconds misses most problems; 0.5-1 second is a common production value.

What can go wrong

0 logs every statement: useful briefly for sampling, too heavy to leave on.

The closest setting on other engines

引擎设置项默认Restart
MySQL long_query_time this page 10 否
PostgreSQL log_min_duration_statement -1 (disabled) 否
SQL Server QUERY_STORE ON (READ_WRITE) 否

Questions about long_query_time

What is the default value of long_query_time in MySQL?

10. 10 seconds (MySQL 8.4).

Does changing long_query_time require a restart?

No. No restart. SET GLOBAL (or SET PERSIST, which also survives restarts) applies to connections opened afterwards; existing connections keep their session value unless they SET it themselves.

When should I change long_query_time?

10 seconds misses most problems; 0.5-1 second is a common production value.

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

// one client for every engine

Check long_query_time 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.