MySQL logs explained: error, slow query, general, and binary logs
Configure MySQL 8.0 and 8.4 logs, interpret slow queries, and manage binary log retention for replication and point-in-time recovery.
A MySQL instance restarts during a deploy. After it comes back, a read endpoint is still slow. Start with the error log to see what happened during restart and recovery. Then look at the slow query log for statements that finished during the affected window. If the deploy changed data and you need to reconstruct those changes, the binary log is a different trail.
This guide uses self-managed MySQL 8.0 and 8.4. The [mysqld] snippets show startup settings. Check actual paths, file permissions, and any persisted overrides before changing them.
Which MySQL log answers which question?
| Log | Start here when you need to know… | Normal server default |
|---|---|---|
| Error log | Why the server failed to start or what it reported during recovery | Active, with a destination that depends on startup settings |
| Slow query log | Which completed statements met the slow-log criteria | Off |
| General query log | What connections and statements the server received in a short capture window | Off |
| Binary log | Which logged changes a replica or recovery needs to replay | On |
1. Error log
[mysqld]
log_error = /var/log/mysql/error.log
Use SHOW GLOBAL VARIABLES LIKE 'log_error'; to check the setting. If the server is down, inspect its service or container configuration instead. The example selects a file at startup. The server needs write access to the directory. When diagnostics go to standard error, the service manager or container runtime can capture them elsewhere.
With the default log_filter_internal filter, log_error_verbosity levels 1, 2, and 3 permit errors, add warnings, and then add informational messages, respectively. Suppression rules can still filter eligible messages. Read the shutdown, startup, and InnoDB recovery entries together to establish the sequence before deciding whether the restart explains the later slowness. MySQL error log configuration
2. Slow query log
[mysqld]
log_output = FILE
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow.log
long_query_time = 1
# log_queries_not_using_indexes = 1
# log_slow_admin_statements = 1
MySQL defaults long_query_time to 10 seconds. One second is an example for the instance in this configuration. Other conditions, such as min_examined_row_limit, also affect what gets recorded. The first commented option can log statements that do not use indexes for row lookups, including some below the time threshold. The second makes eligible administrative statements such as ALTER TABLE candidates for the slow log. Evaluate the volume before enabling either.
log_output applies to both the slow and general logs. FILE makes these file paths relevant, TABLE writes to mysql.slow_log and mysql.general_log, and NONE suppresses output. A runtime SET GLOBAL does not by itself persist across restarts. Existing sessions keep their current long_query_time when you change the global value. Check with a fresh connection. Use startup configuration or, for supported variables, an approved SET PERSIST change if you intend to keep the setting.
In a file entry, Query_time and Lock_time are in seconds. Rows_examined and Rows_sent help you distinguish a scan from a large response. Use a readable copy of the slow log to group repeated statement shapes. The commands require the corresponding MySQL and Percona utilities.
mysqldumpslow -l -s t /path/to/copied/slow.log
pt-query-digest /path/to/copied/slow.log
mysqldumpslow sorts groups by total query time here. The -l flag keeps lock time from being subtracted. pt-query-digest groups queries by fingerprint and provides a more detailed breakdown. Pick a threshold based on the service's latency targets and the volume the server can sustain. MySQL slow query log · mysqldumpslow options · Percona Toolkit
3. General query log
[mysqld]
log_output = FILE
general_log = 1
general_log_file = /var/log/mysql/general.log
The general log records client connections, disconnections, and statements as the server receives them. It can show which SQL a client sent, even if execution later fails. Commit status needs separate evidence. A capture can also contain sensitive SQL, so restrict access to the output.
The example enables logging at startup. For a short production investigation, leave the startup default off and have an authorized operator check the destination, free space, and previous value before running SET GLOBAL general_log = 'ON';. Restore the previous value when the capture ends. Sending the log to a table changes where the records accumulate. The capture window still controls how much data you collect. MySQL general query log · Log destinations
4. Binary log
[mysqld]
log_bin = /var/log/mysql/mysql-bin
binlog_expire_logs_seconds = 604800
max_binlog_size = 1G
sync_binlog = 1
Confirm log_bin on the instance. The binary log carries events for logged changes, including row events when applicable. Replicas consume these events. GTID auto-positioning can identify and request missing transactions, provided the source still has the events it needs to send.
Point-in-time recovery starts with a consistent backup. Preserve the binary logs from its recorded coordinates through the recovery target. You can inspect a copy with mysqlbinlog. Feeding its replay output to a MySQL client applies changes, so validate the recovery sequence on an isolated instance first.
The example sets an expiration age of seven days. Average binary-log growth times retention is a rough disk estimate. Leave room for spikes and large transactions. A transaction stays in one binary-log file, so max_binlog_size is a rotation threshold. sync_binlog=1 synchronizes the binary log before a commit group commits. InnoDB commit durability also depends on innodb_flush_log_at_trx_commit and storage behavior. MySQL binary log · GTID auto-positioning · Point-in-time recovery
5. Other records worth checking
InnoDB uses redo for crash recovery and undo for rollback and consistent reads. For query performance, the Performance Schema table events_statements_summary_by_digest groups captured execution statistics by statement digest. Its summaries can highlight a frequent query shape that rarely crosses the slow-log threshold. Use the slow log for details of recorded executions.
Review errors and slow queries in one place
Where DataKit can read the files, configure log collection for each path and retain instance and service tags. Test a known multiline statement end to end. For standard slow-log files, the MySQL integration documents the mysql.p pipeline. Check its parsed event time, query_time, lock_time, and rows_examined against the original. Choose error-log parsing for the format the server actually emits.
Filter the error log by instance and time, then compare slow queries for the same window. Extracting fields and keeping the SQL text are separate from producing a normalized fingerprint. For recurring symptoms, configure Guance log detection with filters, an evaluation window, and a count threshold. Set retention for errors and slow queries according to how far back you need to investigate.
Frequently asked questions
Does the slow query log slow down MySQL?
The cost depends on the number of records, destination, and storage. Lowering the threshold or including queries that skip index lookups can increase writes substantially. Compare log volume, disk I/O, and query latency under a representative load before keeping a change.
What if I leave the general log on?
The file or log table can grow quickly. If it was off before the investigation, an authorized operator can restore that state with SET GLOBAL general_log = 'OFF';. Restore the startup configuration too if you changed it. Table output still needs a capture limit and cleanup plan.
What should I do if binary logs fill the disk?
Check whether the increase came from a higher write rate, a large transaction, or retention. Before shortening retention or running PURGE BINARY LOGS, check all replicas, including disconnected ones, and the backup recovery window. The source can remove logs an offline replica still needs. Use the supported purge mechanism after those checks. Split large transactions only where the application can tolerate separate commits. MySQL purge behavior
How do I collect logs from a managed MySQL service?
Use the provider's download, export, or subscription option, then parse the exported format. For example, Amazon RDS for MySQL enables the slow and general logs through a parameter group. Check the required output mode for your export method before using any paths in this guide.
Related reading
Contact us
Join the community
to join the community
Try Guance
Start online and pay only for what you use.
Get startedChoose a Guance plan
