How to Fix MySQL Error 4042 (ER_WARN_ADUIT_LOG_MAX_SIZE_AND_PRUNE_SECONDS)

Published
Length
3 min read

Luis Felipe Dias

All posts

You see mysql error 4042 when both audit log size and prune time have non-zero values. To fix it, set one of those two log retention rules back to zero. The database engine uses the symbol ER_WARN_ADUIT_LOG_MAX_SIZE_AND_PRUNE_SECONDS and SQLSTATE HY000 for this warning. Notice that the official symbol has a typo in the word audit. When both rules are active, the maximum size rule wins. The database ignores the prune seconds setting until you change the size limit. Why mysql error 4042 happens

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.

You see mysql error 4042 when both audit log size and prune time have non-zero values. To fix it, set one of those two log retention rules back to zero.

The database engine uses the symbol ER_WARN_ADUIT_LOG_MAX_SIZE_AND_PRUNE_SECONDS and SQLSTATE HY000 for this warning. Notice that the official symbol has a typo in the word audit. When both rules are active, the maximum size rule wins. The database ignores the prune seconds setting until you change the size limit.

Why mysql error 4042 happens in your database

Database teams turn on audit logs to track who runs queries on sensitive tables. Over time, these log files grow large and fill up the local disk. The audit plugin gives you two ways to clean up old log files. You can limit the total byte size of all audit logs. Or you can delete log files older than a set number of seconds.

Still, the audit engine cannot run both cleanup methods at the same time. If a team sets a non-zero number for both rules, the server raises a warning. The warning message states that both audit_log_max_size and audit_log_prune_seconds are set to non-zero. It then tells you that audit_log_max_size takes precedence over the time rule.

This conflict often happens when admins merge old server files with new templates. One admin sets a disk limit to stop storage alerts. Another admin adds a time rule to meet a ninety-day retention policy. Because the size rule wins, the server might delete logs much earlier than expected. High query traffic can fill the size limit in just a few hours.

How to check and fix the audit log conflict

First, check your active audit log variables inside the database server. You do not need to give developers full admin rights to check this. A read-only admin role can view the current system settings and warning logs. Look at the active values for maximum log size and prune seconds.

Next, talk to your security team to pick the right retention method. If disk space is tight, keep the maximum size rule active. Set the prune seconds rule to zero in your server settings file. Make sure you ship old logs to central storage before the server deletes them.

MySQL Access Governance + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If you must keep logs for a set number of days, use prune seconds. Set the maximum size rule to zero so the time rule can work. Keep in mind that time pruning only works when log rotation is active. Check that your server rotates log files based on file size first. Once rotation is on, the server will prune rotated files by age.

Always test these changes in a staging setup before touching production. Apply the updated setting during a low-traffic window to avoid log locking delays. After you update the rule, query the warning log to confirm the code is gone. Finally, update your startup file so the fix stays after a reboot.

Better ways to manage database audit trails

Relying only on local database files for audit trails creates extra work for teams. Local files fill up disks and require careful rotation and pruning rules. If an attacker gains host access, they might also alter local log files.

A better pattern is to capture query logs at the network proxy layer. When all user sessions pass through a central proxy, you get one audit stream. You do not have to tune file size limits on every single database node. The proxy records who ran each query and sends events to your log store. You can also add dynamic data masking to rewrite emails, phone numbers, or card numbers in results. This keeps sensitive data out of local logs while meeting audit rules.

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 mysql error 4042 stop queries from running?

No, code 4042 is a warning under SQLSTATE HY000, not a fatal error. Your database queries and apps will keep running as normal. Still, your log retention will follow the size limit instead of the time limit.

Why is the word audit spelled wrong in the error symbol?

The official symbol ER_WARN_ADUIT_LOG_MAX_SIZE_AND_PRUNE_SECONDS has a typo made in the server source code. The letters u and d are swapped in the word audit. The database keeps this exact spelling so existing monitoring tools do not break.

Which audit log rule should I keep active in production?

Use the maximum size rule if your server has small disks that fill up fast. Use the prune seconds rule if your security policy requires keeping logs for a fixed time. Never leave both rules set above zero at the same time.

The query runs. The emails stay hidden.