How to Fix MySQL Error 3145 (ER_INVALID_JSON_CHARSET_IN_FUNCTION)
You get mysql error 3145 when a query passes non-UTF8 text into a JSON function. To fix it, convert the input text or column to UTF8 before the function runs. MySQL logs this failure under the symbol ER_INVALID_JSON_CHARSET_IN_FUNCTION with SQLSTATE 22032. The server stops the query and says that UTF8 character data is required. This rule protects the database from broken documents and bad string bytes. You will see this failure during data imports, app updates, or legacy table joins. Why mys
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 3145 when a query passes non-UTF8 text into a JSON function. To fix it, convert the input text or column to UTF8 before the function runs.
MySQL logs this failure under the symbol ER_INVALID_JSON_CHARSET_IN_FUNCTION with SQLSTATE 22032. The server stops the query and says that UTF8 character data is required. This rule protects the database from broken documents and bad string bytes. You will see this failure during data imports, app updates, or legacy table joins.
Why mysql error 3145 happens in your database
The JSON standard requires UTF8 text for all valid documents. MySQL enforces this rule inside every built-in JSON function. When a query sends Latin1 or binary bytes into a JSON function, the engine rejects it. That rejection triggers mysql error 3145 right away.
One common cause is a legacy table that still uses an older character set. If you read a column from that table and build a JSON object, the query fails. The column holds non-UTF8 text, so the function refuses to read it.
Client session settings also cause this issue in production. An app might open a database session using a Latin1 client setting. Any text literal sent over that session takes on the client character set. When the query passes that literal to a JSON parser, the server blocks the request.
Binary columns and raw byte strings create the same problem. Developers sometimes store text inside binary fields or temporary tables without a text label. MySQL treats untyped bytes as binary data, which fails the UTF8 check inside JSON calls.
How to find and fix the character set mismatch
Start by reading the full error message in your app log. The message names the exact JSON function and the specific input string that failed. This tells you which part of the query holds the wrong character set.
Just-in-Time Access + JSON Web Tokens (JWT): architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Next, check the character set of every table and column in that query. Look at the schema metadata to see if any text fields use Latin1 or binary types. Also check the character set of your active client session and database connection pool.
You can fix the query fast by converting the input text to UTF8 inside the query. This approach works well when you cannot change the table schema right away. It lets the query run while your team plans a permanent schema update.
For a permanent fix, update the app client settings so every session uses UTF8 by default. If a legacy column holds old text, plan a safe schema change to convert that column. Test the conversion on a staging copy first to make sure no characters get lost.
Safe ways to debug production database errors
Debugging character set failures in production requires care. Engineers often need to inspect table metadata and run test queries on live data. Giving out full admin credentials for a simple check creates major security risks.
Instead, give engineers read-only roles that allow schema checks without write rights. Make sure every debug query runs through a central control point that logs the query text. If a table holds sensitive fields like emails, phone numbers, card numbers, or national IDs, apply data masking. Masking rewrites matched fields in results so debug checks stay safe.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL, inline in the MySQL wire protocol. On every query an AI agent or human runs against production MySQL, RDS, or Aurora, hoop.dev decides to pass, mask, block, or hold it for review.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails, which refuse banned queries with a native MySQL error or hold risky ones for approval. On the response path, hoop.dev data masking rewrites string values in returned rows in memory, and every decision is logged. See the MIT-licensed project on GitHub.
Frequently asked questions
What does ER_INVALID_JSON_CHARSET_IN_FUNCTION mean in MySQL?
It means a built-in JSON function received text that is not encoded in UTF8. MySQL requires UTF8 data for all JSON operations and stops the query with SQLSTATE 22032.
Can client connection settings trigger mysql error 3145?
Yes, if your app connects with a non-UTF8 character set, string literals use that old encoding. Passing those literals into a JSON function will trigger error 3145 even if your tables use UTF8.
How do I fix error 3145 without changing my table schema?
You can cast or convert the text value to UTF8 inside the query before the JSON function reads it. You should also set your app database driver to use UTF8 for all new sessions.
Related guides
In this post