MySQL Slow Query Log Format: Fields Explained (Query_time, User@Host)
Published
One entry per statement that ran longer than long_query_time (or every statement, when set to 0): a # Time line, the account and client (User@Host with the connection Id), timing and row counts, a SET timestamp statement giving the start time, and the statement itself.
Official documentation: MySQL 8.4 Reference Manual: The Slow Query Log · MySQL 8.4 Reference Manual: The Error Log
Sample record
# Time: 2024-01-15T09:00:01.412871Z
# User@Host: app_user[app_user] @ app-server [10.0.0.10] Id: 12
# Query_time: 0.045213 Lock_time: 0.000112 Rows_sent: 25 Rows_examined: 25
use shop;
SET timestamp=1705309201;
SELECT id, name, email FROM users WHERE active=1 LIMIT 25; From the LogTriage parser test corpus — synthetic data, no real hosts or users.
Field reference
| Field | Type | Meaning | Why it matters for security |
|---|---|---|---|
| Timee.g. 2024-01-15T14:30:13.456211Z | date-time | When the entry was written, after the statement finished — in UTC unless log_timestamps is SYSTEM. | The end of the statement; SET timestamp gives its start. |
| User@Host › usere.g. webapp | string | The account the statement ran as. The line is written user[authenticated user] @ host [address]; the bracketed name can differ when a proxy or anonymous account matched. | An application account running hand-typed queries, or root at all, is worth a look. |
| User@Host › hoste.g. app-server | string | The client's host name, when the server resolved it; empty with skip_name_resolve or when the address has no name. | Do not trust names alone — the address next to it is what connected. |
| User@Host › addresse.g. 185.220.101.42 | IP address | The client's IP address; empty for connections over the local socket (localhost []). | Any address outside your application servers talking to the database directly is the first thing to explain. |
| Ide.g. 8812 | number | The connection (thread) ID, the same number the general log, the processlist and the error log use. | Follow one session across logs, and KILL it if it is still running. |
| Query_timee.g. 12.456003 | seconds | MySQL: "The statement execution time in seconds." | Long runs on big tables are often a dump in progress. |
| Lock_timee.g. 15.701332 | seconds | MySQL: "The time to acquire locks in seconds." | A DROP or ALTER waiting on locks blocks the application while it waits. |
| Rows_sente.g. 50000 | number | MySQL: "The number of rows sent to the client." | The size of what left — tens of thousands of rows from users or payment tables is exfiltration. |
| Rows_examinede.g. 5000000 | number | MySQL: "The number of rows examined by the server layer (not counting any processing internal to storage engines)." | Full scans by an unfamiliar client are enumeration or a dump. |
| SET timestampe.g. 1705329001 | Unix time | The statement MySQL writes before each logged statement, "that includes a timestamp, indicating when the slow statement began executing". | Use it for timelines; it is the start time in seconds since 1970 (UTC). |
| querye.g. DROP TABLE audit_log, user_sessions; | SQL | The statement as the client sent it, after an optional use <database>; line when the default database changed. | UNION SELECT, SELECT * on credential tables, DROP and TRUNCATE are the patterns to look for. |
Have one of your own records? Paste it into the log line explainer and each field is explained from this table, with times, codes and addresses decoded — in your browser.
What it records
The slow query log contains statements that took longer than long_query_time seconds (and, optionally, statements that use no index). Each entry, as the MySQL manual describes, has # lines with the time, the account and client, and Query_time, Lock_time, Rows_sent and Rows_examined; then a use statement when the default database changed, a SET timestamp statement with the start time, and the statement itself. With log_slow_extra the third line gains the thread ID, error number, bytes received and sent, handler counters and start and end times.
Set long_query_time to 0 and the slow log becomes a record of every statement with who sent it and how many rows it returned — the one MySQL log that measures how much data a client took. Each time mysqld opens the file it writes three header lines (the binary and version, the port and socket, and a column header), which parsers should skip.
The malicious sample has a UNION SELECT pulling 50,000 rows of user and admin credentials from an outside address with the application’s account, root on the local socket reading 10,000 rows from credit_cards, and a second outside address dropping the audit and session tables.
Where to get it
- File.
slow_query_log_file(by defaulthost_name-slow.login the data directory), withlog_output=FILE. - Table. With
log_output=TABLE, entries go tomysql.slow_loginstead — query it with SQL. - Managed services. Amazon RDS and Aurora publish the slow log to CloudWatch Logs; Cloud SQL to Cloud Logging; Azure Database for MySQL to diagnostic settings.
- Error log.
log_errorholds connection errors and access denials; it is a separate file.
# Statements that returned more than 10,000 rows, with the client
awk '/^# User@Host/{who=$0} /^# Query_time/{split($0,a,"Rows_sent: "); split(a[2],b," "); if (b[1]>10000) print who" rows="b[1]}' slow.log
Parsing pitfalls
- Multi-line entries. Statements span lines; an entry ends at the next
# Time:or# User@Host:line. - Optional lines.
# Time:is omitted when several entries share a second in older versions;useappears only when the database changed. - Two times.
# Timeis when the entry was written,SET timestampwhen the statement started. - Empty host or address.
user[user] @ [203.0.113.5]has no host name;@ localhost []is a socket connection. - Mixed field sets. With
log_slow_extraswitched on mid-file, entries have different numbers of fields. - Header lines. Three lines after each log open or flush are not entries.
Detection ideas
- Direct access from outside: User@Host addresses that are not your application servers.
- Injection through the application: UNION SELECT,
information_schemareads andSLEEP()from the application account. - Bulk reads: large Rows_sent from user, payment or credential tables.
- Destructive statements: DROP, TRUNCATE, and DELETE or UPDATE without a WHERE clause — especially on audit tables.
- Privileged accounts: root or admin accounts running queries outside maintenance windows.
The free browser analyzer reads MySQL slow, error and general logs and runs these checks locally.
Sending MySQL to an LLM
One megabyte of this format is about 555,866 tokens on current Claude models and 386,173 on GPT models, measured with the models' own tokenizers — so a gigabyte sent raw to Claude Sonnet 5.5 costs about $1,112 in input tokens alone (prices of 2026-10-24). Estimate your own volume →
Frequently Asked Questions
- How do I enable the MySQL slow query log?
- Set slow_query_log=ON, slow_query_log_file to a path and long_query_time to a threshold in seconds, in the configuration file or with SET GLOBAL. For security investigations long_query_time=0 logs every statement, at the cost of volume; log_slow_extra=ON adds the thread ID, error number, bytes sent and start and end times.
- What is the difference between Rows_sent and Rows_examined?
- Rows_examined is how many rows the server layer read to answer the statement; Rows_sent is how many it returned to the client. A large Rows_examined with a small Rows_sent is an inefficient query; a large Rows_sent is a lot of data leaving the database, which is what matters for exfiltration.
- Does the slow query log record failed logins?
- No. Connections and access-denied errors are in the error log (Access denied for user … (using password: YES), with log_error_verbosity at 3) and in the general query log. The slow query log only records statements that ran, so pair it with the error log to see guessing before a successful login.
- Why does the slow log contain SET timestamp lines?
- MySQL writes a SET timestamp statement before each logged statement so that the file can be replayed with the original time, and it tells you when the statement began executing. The # Time line is when the entry was written, after the statement finished, so the two differ by roughly the query time.
Analyze a MySQL file in your browser
The free analyzer detects this format, parses every field above and flags attack patterns — the file never leaves your machine. For threat-intel enrichment and an AI-written incident report, run it through LogTriage.
Investigating something right now? LogTriage checks every address in the file against threat intelligence and writes the incident report: 10 analyses a month free. The incident pack adds the in-depth AI analysis and files up to 100 MB: 25 analyses for $19, one payment, no subscription. Pricing
How this page was made. The official definitions, field names and examples on it are copied by script from the sources it links and re-checked against them on every build. The investigation advice was drafted with AI from those sources and passed a separate review before publishing. What is checked, and how · found a mistake? [email protected]