SyntaxStudy
Sign Up
MySQL Intermediate 4 min read

Slow Query Log

Slow Query Log

Enable the slow query log to capture queries that exceed a time threshold. Use mysqldumpslow or tools like pt-query-digest to analyze them.

Example
-- Enable slow query log
SET GLOBAL slow_query_log = 1;
SET GLOBAL long_query_time = 1;  -- seconds
SET GLOBAL slow_query_log_file = '/var/log/mysql/slow.log';

-- Show current slow query settings
SHOW VARIABLES LIKE 'slow%';
SHOW VARIABLES LIKE 'long_query_time';
Pro Tip

Start with long_query_time = 1 second, then lower it once the obvious slow queries are fixed.