Databases 5 min read

Master MySQL Log Files: Error, Slow Query, and Binlog Management Guide

This article explains MySQL’s various log files—including error log, slow query log, binary log and general query log—detailing how to locate, configure, view, and analyze them using MySQL commands, and how to adjust settings such as long_query_time and log_output for optimal performance.

Java Backend Technology
Java Backend Technology
Java Backend Technology
Master MySQL Log Files: Error, Slow Query, and Binlog Management Guide

Experiment environment: MySQL Community Server (GPL) 5.7.17 on Ubuntu 16.04.

1. MySQL Log File Classification

Common MySQL logs include:

Error log

Slow query log

Binary log (binlog)

General query log

2. Error Log

Official documentation: https://dev.mysql.com/doc/refman/5.7/en/error-log.html

The MySQL error log records serious warnings, errors, and detailed information about each server start and shutdown.

You can find the error‑log file location with: show variables like 'log_error'\G; Images illustrate the command output.

3. Slow Query Log

Official documentation: https://dev.mysql.com/doc/refman/5.7/en/slow-query-log.html

The slow query log records statements whose execution time exceeds the long_query_time threshold (default 10 seconds).

Check the current threshold and whether the log is enabled:

show variables like 'long_query_time'\G;
show variables like 'slow_query_log'\G;

Enable the slow query log: set global slow_query_log='ON'; Find the default slow‑query log file: show variables like 'slow_query_log_file'\G; By default the file is named host_name-slow.log.

View the log using mysqldumpslow:

sudo mysqldumpslow /var/lib/mysql/xuliugen-slow.log

For more options, run man mysqldumpslow.

Change the storage format from file to table: show variables like 'log_output'\G; Set output to TABLE: set global log_output='TABLE'; The slow queries will then be stored in the mysql.slow_log table: show create table mysql.slow_log\G; Test the slow query log by executing a deliberately slow statement: select sleep(10); Then query the table to see the recorded entry: select * from mysql.slow_log\G; MySQL 5.7 also provides two additional variables:

log_slow_admin_statements
log_queries_not_using_indexes

By default, administrative statements and queries that do not use indexes are not logged; adjusting these settings in development can help, but they are usually disabled in production to avoid excessive log growth.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

mysqlslow-queryDatabase Administrationerror logLog Files
Java Backend Technology
Written by

Java Backend Technology

Focus on Java-related technologies: SSM, Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading. Occasionally cover DevOps tools like Jenkins, Nexus, Docker, and ELK. Also share technical insights from time to time, committed to Java full-stack development!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.