// mysql · logging & diagnostics

long_query_time

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

Padrão
10
Range
0 to 31536000 seconds, with microsecond resolution
Restart needed
Não
Default checked on
MySQL 8.4 LTS

O que faz

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

Valor padrão

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

MotorConfiguraçãoPadrãoRestart
MySQL long_query_time this page 10 Não
PostgreSQL log_min_duration_statement -1 (disabled) Não
SQL Server QUERY_STORE ON (READ_WRITE) Não

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.