How to Fix MySQL Error 4085 (ER_CANNOT_PURGE_BINLOG_WITH_BACKUP_LOCK)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 4085 when you try to delete binary logs during an active backup. To fix it, wait for the backup session to release its lock first. Database servers use binary logs to record every data change and table update. Storage fills up fast when your database handles heavy write traffic all day. Admins must clear out old log files to free up disk space. Still, backup jobs also need those exact same files to create a clean copy. When a log cleanup job overlaps with a backup job, the d

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 get mysql error 4085 when you try to delete binary logs during an active backup. To fix it, wait for the backup session to release its lock first.

Database servers use binary logs to record every data change and table update. Storage fills up fast when your database handles heavy write traffic all day. Admins must clear out old log files to free up disk space. Still, backup jobs also need those exact same files to create a clean copy. When a log cleanup job overlaps with a backup job, the database blocks the deletion.

Why mysql error 4085 happens in your database

In the database engine, this failure maps to symbol ER_CANNOT_PURGE_BINLOG_WITH_BACKUP_LOCK and SQLSTATE HY000. The server reports that it could not purge binary logs due to another session. That other session is holding an active instance backup lock right now. You must wait for that session to release the lock before trying again.

The instance backup lock is a light safety feature inside the database engine. It allows normal data reads and writes to continue during an online backup. At the same time, it stops actions that would break the backup files. It blocks table structure changes and prevents the removal of binary log files.

This clash often happens when automated maintenance scripts run at the wrong time. Your disk cleanup script might try to remove logs at midnight. If a full database backup starts just before midnight, the two tasks collide. The backup tool locks the instance to copy data and log positions safely. When the cleanup script runs, the engine rejects it with code 4085.

Orphaned database sessions can also trigger this issue in your production cluster. If a backup tool crashes or loses its network path, its session might hang. That stuck session keeps holding the backup lock until the server drops it.

How to find the lock and fix the error safely

Start by checking the active process list on your database server. Look for any open session that is running a backup tool or holding a lock. Check how long that session has been open and whether data is still moving.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If a real backup is still running, the safest fix is patience. Let the backup job finish its work and release the lock on its own. Once the backup ends, run your binary log purge command again. The server will remove the old log files right away without any error.

Sometimes you will find that the backup job failed hours ago. The client app is gone, but the server session is still stuck open. In this case, ask a database admin to stop that specific background session. Never restart the whole database server just to clear a stuck backup lock. Stopping only the dead session drops the lock while keeping user traffic safe.

How to prevent backup lock conflicts

You can stop this error from coming back by spacing out your cron jobs. Check the schedule for your backup tool and your log purge scripts. Move the log cleanup task so it runs after the backup window closes.

Better yet, rely on the built-in log expiration settings in your database engine. Set an automatic expiration period so the engine manages log removal on its own. When a backup lock is active, the engine waits until the lock clears. You should also avoid granting broad admin rights to routine maintenance scripts. Give each script only the exact role it needs to do its job.

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 4085 stop normal app reads and writes?

No, normal app reads and writes keep working fine during this error. The backup lock only blocks file deletions and table structure changes.

Can I force the database to purge binary logs during a backup?

No, you cannot force a binary log purge while the backup lock is active. Forcing it would corrupt the backup copy that is running.

What happens if my disk fills up while waiting for the backup lock?

If the disk is full, you may need to cancel the active backup session. Once the session stops, the lock drops and you can purge old logs.

The query runs. The emails stay hidden.