How to Fix MySQL Error 3142 (ER_INVALID_JSON_BINARY_DATA)
You see mysql error 3142 when the database reads a corrupt binary JSON value. You can fix it by finding the bad row and writing valid JSON text. MySQL stores JSON documents in an internal binary format for fast reading. This error uses the symbol ER_INVALID_JSON_BINARY_DATA and the SQLSTATE code HY000. The server returns the message that the JSON binary value contains invalid data. When the engine hits broken bytes in this format, it stops the query right away. Your team must find the damaged r
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 3142 when the database reads a corrupt binary JSON value. You can fix it by finding the bad row and writing valid JSON text.
MySQL stores JSON documents in an internal binary format for fast reading. This error uses the symbol ER_INVALID_JSON_BINARY_DATA and the SQLSTATE code HY000. The server returns the message that the JSON binary value contains invalid data. When the engine hits broken bytes in this format, it stops the query right away. Your team must find the damaged records and replace them with clean data.
What causes mysql error 3142 in your database
The database engine does not expect raw binary input from outside apps. Instead, it turns plain JSON text into its own binary format during writes. Several issues can break these stored bytes and trigger mysql error 3142.
First, disk corruption or bad memory can flip bits inside your data files. When a query reads that page from disk, the binary check fails. Second, raw binary imports or faulty migration tools can write bad bytes into a column. If a tool skips the text parser, it can write invalid binary sequences.
Third, replication bugs between different server versions can damage binary JSON payloads. A replica might read a binary log event that uses an unknown internal structure. Finally, a bug in a custom storage plugin or driver can send malformed bytes. In every case, the engine rejects the value to stop further data loss.
How to find and fix the broken JSON rows
You should never grant broad admin rights to fix data errors in production. Start by running a read query with a limited role to find the bad row. Query slices of the table by primary key range until the error appears. Narrow the key range step by step to isolate the exact primary key.
During this search, your database might hold private user details inside JSON columns. A data masking layer can rewrite emails, phone numbers, card numbers, and national IDs in results. This lets your team check rows without exposing sensitive fields in query outputs.
JSON Web Tokens (JWT) + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Once you find the broken row, do not try to read the JSON field. Update that row by primary key and write a clean JSON text string. If you cannot rebuild the value from app logs, pull it from a clean backup. After you replace the bad record, run a table check to verify disk health. If disk errors caused the damage, move your data to a healthy storage volume.
How to prevent binary JSON corruption
Always send plain JSON text strings from your app and let the server parse them. Avoid tools that write directly to underlying table files while the server runs. Test your backup files often to make sure your saved JSON columns read cleanly.
Keep your primary and replica servers on matching versions to avoid binary log conflicts. Use strict SQL modes so the database rejects bad writes before they reach the disk. Monitor your host hardware logs for memory or storage faults that could harm files. You should also review all write queries that touch sensitive tables in production. Approval rules help your team catch risky bulk imports before they break live data.
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_INVALID_JSON_BINARY_DATA mean in MySQL?
It means the internal binary structure of a stored JSON value is broken. The database engine cannot parse the bytes and stops your query with SQLSTATE HY000.
Can a syntax error in a JSON string cause error 3142?
No, plain text syntax mistakes trigger a different parsing error during insert or update. Error 3142 only happens when the internal binary format is already corrupt.
How can I delete or fix a row if reading it throws error 3142?
Update or delete the row using only its primary key in your filter clause. Do not read or filter by the broken JSON column during the write query.
Related guides
In this post