MySQL, EXPLAIN and

Syntax

SHOW VARIABLES LIKE 'slow_query%';
SET GLOBAL slow_query_log = ON;
EXPLAIN [FORMAT=JSON] SELECT ...;
SHOW PROCESSLIST;

Parameters

ParametersDescriptionExamplesLevel
slow_query_log SET GLOBAL slow_query_log = ON; Common
long_query_time () SET GLOBAL long_query_time = 1; Common
EXPLAIN EXPLAIN SELECT * FROM orders WHERE user_id = 1001; Common
SHOW PROCESSLIST and SHOW FULL PROCESSLIST; Common
SHOW STATUS SHOW GLOBAL STATUS LIKE 'Threads%'; Advanced

Examples

and

-- SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 1; -- 1 SET GLOBAL log_queries_not_using_indexes = ON; -- -- SHOW VARIABLES LIKE 'slow_query_log_file'; -- mysqldumpslow -- mysqldumpslow -s t -t 10 /var/log/mysql/slow.log
long_query_time 1-2

EXPLAIN

EXPLAIN SELECT o.order_no, u.username
FROM orders o
JOIN users u ON o.user_id = u.id
WHERE o.status = 1 AND o.created_at > '2026-05-01'
ORDER BY o.created_at DESC; -- : -- type: ALL() < index < range < ref < const
-- key: -- rows: ()
-- Extra: Using filesort() Using temporary()
type range Level, ALL

and

-- SHOW FULL PROCESSLIST; -- SELECT * FROM information_schema.PROCESSLIST
WHERE COMMAND != 'Sleep' AND TIME > 10
ORDER BY TIME DESC; -- KILL 12345; -- 12345 ID
KILL,

-- InnoDB ( 60-80%)
SHOW VARIABLES LIKE 'innodb_buffer_pool_size'; -- SHOW VARIABLES LIKE 'max_connections';
SHOW STATUS LIKE 'Threads_connected'; -- ANALYZE TABLE orders; -- SELECT * FROM sys.schema_unused_indexes; -- MySQL 8.0+
innodb_buffer_pool_size Parameters

Common Errors

(), ANALYZE TABLE New;,
Too many connections., max_connections,

Tips

Related Commands