How to Fix MySQL Error 3648 (ER_COULD_NOT_APPLY_JSON_DIFF)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3648 when a replica fails to apply a partial JSON update. You fix it by syncing the broken row and checking your binary log rules. MySQL uses the symbol ER_COULD_NOT_APPLY_JSON_DIFF and SQLSTATE HY000 for this failure. The error log notes that the engine could not apply a JSON diff in a specific table and column. When this happens, the replication thread stops right away to protect your data. What causes mysql error 3648 in your database cluster MySQL can send small JSON

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 3648 when a replica fails to apply a partial JSON update. You fix it by syncing the broken row and checking your binary log rules.

MySQL uses the symbol ER_COULD_NOT_APPLY_JSON_DIFF and SQLSTATE HY000 for this failure. The error log notes that the engine could not apply a JSON diff in a specific table and column. When this happens, the replication thread stops right away to protect your data.

What causes mysql error 3648 in your database cluster

MySQL can send small JSON diffs instead of full documents to save network bandwidth. The primary server logs only the changed paths in the binary log. The replica reads this diff and applies it to its local copy of the row.

This process breaks when the JSON value on the replica does not match the primary. If a path in the diff is missing on the replica, the update fails. The replica then throws error code 3648 and stops its worker thread.

Data drift is the most common reason for this mismatch. A team member or an app might write directly to the replica by mistake. Even a tiny change to the local JSON structure will break future partial updates.

Another cause is a bug or mismatch in how servers handle partial row updates. If the primary sends a partial diff that the replica cannot parse, replication stops. Network drops do not cause this directly, as checksums catch bad packets first.

How to diagnose and fix the failure safely in production

Start by reading the replica error log or checking the replication status output. The error message gives you the exact table name and the JSON column name. Write down the primary key or position where the worker thread stopped.

Next, compare the JSON document on the primary with the row on the replica. Do not grant broad superuser roles to the whole team during this check. Use a read-only role to inspect both servers safely.

JSON Web Tokens (JWT) + MySQL Access Governance: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

If the documents hold sensitive data, make sure your query tools apply data masking. Masking rewrites matched fields like emails, phone numbers, card numbers, or national IDs in results. This lets engineers compare the JSON keys without exposing private customer details.

To fix the broken state, copy the full JSON value from the primary server. Update the matching row on the replica so both documents are identical again. Do not skip the transaction blindly, or your replica data will stay wrong.

Once the row matches, start the replication thread and watch the worker status. If the error comes back, change your binary log setting to send full JSON rows. Sending full JSON documents uses more bandwidth, but it stops diff errors for good.

How to prevent JSON diff drift on replicas

Always turn on read-only mode on every replica in your database cluster. This simple rule stops apps and operators from changing replica rows by mistake. Only the replication thread and admin tasks should write to a replica.

Keep your primary and replica servers on the exact same database engine release. Matching versions make sure both sides handle JSON binary paths the same way. Run regular checksum checks during slow hours to catch silent data drift early.

Limit who can run direct write queries on your production database hosts. Route admin work through controlled workflows with peer review for every manual change. When nobody edits rows by hand, partial JSON updates stay in sync.

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

What does ER_COULD_NOT_APPLY_JSON_DIFF mean in MySQL?

It means the database could not apply a partial JSON change to a column. The target JSON document did not have the structure expected by the diff operation.

Can I skip mysql error 3648 to resume replication?

Skipping the transaction is unsafe because the JSON column on the replica stays out of sync. Future updates to that same row will fail with the exact same error.

Does turning off partial JSON updates hurt database speed?

Sending full JSON documents increases binary log size and network traffic for large rows. Still, local query speed stays the same and replication becomes much more reliable.

The query runs. The emails stay hidden.