Lesson 69/100

Tutorials MySQL Tutorial

Slow Query Logs — Complete Guide

Slow Query Logs — Complete Guide: free step-by-step lesson with examples, common mistakes, and interview tips — part of MySQL Tutorial on Toolliyo Academy.

On this page

MySQL Tutorial · Lesson 69 of 100

Slow Query Logs

Basics ✓Advanced

Advanced · 2 — Production · ~10 min · MySQL — Indexing & Performance

What is this?

Slow query log records statements exceeding long_query_time seconds. Turn it on in dev/staging to find bad SQL before users complain.

Why should you care?

One missing index shows up as thousands of 2-second queries in log — fix once, save daily.

See it live — copy this example

Run in MySQL Workbench or the mysql CLI.

SET GLOBAL slow_query_log = ON;
SET GLOBAL long_query_time = 0.5;
SET GLOBAL log_output = 'TABLE';
SELECT * FROM mysql.slow_log ORDER BY start_time DESC LIMIT 5;

What happened?

  • long_query_time 0.5 logs queries over half second.
  • log_output TABLE writes to mysql.slow_log queryable via SQL.
  • Production often uses FILE + pt-query-digest.

Practice next

  1. Enable slow log in local my.cnf.
  2. Run intentional full scan SELECT.
  3. Read mysql.slow_log or slow.log file.
  4. log_queries_not_using_indexes = ON in dev — noisy but educational.
  5. Use pt-query-digest on slow.log if installed.

Remember

Logs queries above time threshold. TABLE or FILE output options. Feed logs to digest tools for patterns.

DataFlow weekly DBA review

Top 10 slow patterns from log drive index sprint every Monday.

Outcome: Regression caught when deploy adds bad JOIN.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior Detailed
Explain SQL queries in the context of MySQL.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define SQL queri…
Mid Detailed
What are common mistakes teams make with Schema design when using MySQL?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Schema de…
Senior Detailed
How would you debug a production issue related to Transactions in a MySQL application?
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Transacti…
Junior Detailed
Describe a real-world scenario where Normalization mattered in a MySQL project.
Short answer: Interviewers want a crisp definition, a practical example from your projects, and awareness of trade-offs—not textbook dumps. Explain a bit more How to structure your answer (60–90 seconds) Define Normaliza…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

MySQL Tutorial
Course syllabus

MySQL Tutorial

MySQL — Foundations
MySQL — Queries & Clauses
MySQL — Joins & Relationships
MySQL — Functions & Window Functions
MySQL — Transactions & Concurrency
MySQL — Stored Procedures & Triggers
MySQL — Indexing & Performance
MySQL — Advanced MySQL
MySQL — Security & Cloud MySQL
MySQL — Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details