MySQL Query Log

Published
Length
3 min read

Luis Felipe Dias

All posts

The mysql query log records every SQL statement that hits a MySQL server. Database teams use it to check query timing and audit who ran what. MySQL offers two main logs for tracking statement activity across your servers. The general log captures all statements as they arrive from clients and apps. The slow log records only statements that take too long to finish. Both logs help engineers see what apps and users do inside the database. How the mysql query log works in practice When a user or

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

The mysql query log records every SQL statement that hits a MySQL server. Database teams use it to check query timing and audit who ran what.

MySQL offers two main logs for tracking statement activity across your servers. The general log captures all statements as they arrive from clients and apps. The slow log records only statements that take too long to finish. Both logs help engineers see what apps and users do inside the database.

How the mysql query log works in practice

When a user or app sends a query, MySQL parses the request. If the general log is on, the engine writes the command first. It writes this entry before the database even runs the SQL statement. That means failed queries still show up in the log file.

The slow log works at the end of the query run instead. MySQL tracks how long the query takes to read and write rows. If the time beats your threshold, the engine logs the slow statement. Engineers read these entries to find missing indexes and fix slow pages.

Modern teams also let AI agents query MySQL to answer business questions. An agent can send hundreds of read queries in just a few seconds. The mysql query log captures each of those agent requests in order. You can write log data to a local file or a system table. Many teams ship these files to a central log tool for review.

Security and operational tradeoffs of native logging

Turning on the full general log adds heavy disk work to MySQL. Every single query forces the server to write extra text to storage. On a busy system, this extra work slows down real app traffic. Log files also grow fast and can fill up a disk drive. Because of this, most teams leave the general log off in production.

Native logs also leave major security gaps during an active database session. Most teams still share a few static database roles across many engineers. When five people use the same role, the log shows one shared name. You cannot tell which actual person ran a bad delete statement.

MySQL Access Governance + Log Aggregation & Correlation: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static roles also do not control what happens inside an open session. Once a user logs in, they can query any table in that role. If they run a select on customer rows, raw data comes right back. The mysql query log only tells you about the leak after it happens. Worse, the log itself stores raw text from the queries people run. If a query includes an email or card number, the log saves it. Now your plain log files hold sensitive data like phone numbers too.

Closing audit and data gaps in MySQL sessions

To fix these gaps, teams put a control layer in front of MySQL. Instead of sharing static database keys, users log in with their own identity. Each query in the log then maps to a real person or agent. You get a clean audit trail without turning on the heavy general log.

A query control layer can also inspect results before they reach the client. Dynamic data masking rewrites matched fields in results during the active session. It replaces emails, phone numbers, card numbers, and national IDs with safe masks. Engineers and AI agents still run their queries, and logs stay clean.

Inspect every MySQL query and response in flight

Static grants and network rules block bad logins. They cannot pause a risky query for review or mask emails in a result set. By design, hoop.dev sits inline in the MySQL protocol as a sidecar for your MySQL. For every plain query, prepared statement, or cursor an agent or human runs in production, hoop.dev decides to pass, mask, block, or hold it for review.

First, hoop.dev guardrails block banned actions before MySQL runs them, and an AI Analyzer you configure can score intent or escalate for approval. Next, hoop.dev data masking rewrites sensitive string columns in results in memory, and every verdict goes to the audit trail. Find the open-source binary on GitHub.

Frequently asked questions

Does the mysql query log slow down production databases?

Yes, the general log adds disk writes for every statement that runs. High traffic databases can slow down fast when this log is active. Most teams only turn it on for short tests or use external auditing.

What is the difference between the general log and the slow log?

The general log records every single query sent to the MySQL server. The slow log only records queries that take longer than your time limit. Teams use the general log for audits and the slow log for speed.

Can the mysql query log expose sensitive user data?

Yes, the log writes the exact text of every SQL statement. If a query contains card numbers or national IDs, those values sit in plain text. You must restrict who can read the log files on your servers.

The query runs. The emails stay hidden.