MySQL Slow Queries: Turn On the Right Logging

Symptom

Dashboard says MySQL is the bottleneck; no slow queries logged.

Root cause

Slow log off, or long_query_time set above your problem threshold.

Fix, in order

1. Log queries over 200ms, no table scans requiredSET GLOBAL slow_query_log=1; SET GLOBAL long_query_time=0.2;
2. Find it without the logSELECT * FROM performance_schema.events_statements_summary_by_digest ORDER BY SUM_TIMER_WAIT DESC LIMIT 5;
3. Index from the digest, not from guessesEXPLAIN <worst query>

Prevent it coming back

Digest summaries always on; slow log for the deep dives.

Run it on clean infra

Spinning up a fresh box to reproduce or escape this error?

Managed cloud hosting

Related

Cloud & DevOps tool comparisons · Hardware build guides

NinjaOps publishes free engineering guides. Some outbound links are affiliate links: they cost you nothing and support the site.

Last reviewed 2026-10-02 · NinjaOps SEO grid · DevOps blog