How to Fix MySQL Error 3987 (ER_FUNCTION_DOES_NOT_SUPPORT_CHARACTER_SET)
You get mysql error 3987 when a built-in database function receives text in a character set it cannot read. To fix it, convert the input text to a supported character set before calling the function. Database teams often see this failure after an upgrade or a schema change. Legacy tables might hold older text formats that newer text functions reject. Understanding how the engine handles text encoding helps you resolve this fast. Root causes of mysql error 3987 in the database engine The data
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 3987 when a built-in database function receives text in a character set it cannot read. To fix it, convert the input text to a supported character set before calling the function.
Database teams often see this failure after an upgrade or a schema change. Legacy tables might hold older text formats that newer text functions reject. Understanding how the engine handles text encoding helps you resolve this fast.
Root causes of mysql error 3987 in the database engine
The database engine maps this failure to symbol ER_FUNCTION_DOES_NOT_SUPPORT_CHARACTER_SET under SQLSTATE HY000. The server returns a message stating the named function does not support the given character set. This happens during query execution when the parser checks data types.
Each text column, table, and client link has a set encoding. Some newer string, regular expression, or document functions only accept standard Unicode text. If your query sends binary strings or legacy encodings into those functions, the engine stops the query.
Mismatched client settings also trigger this problem during live sessions. An app might open a session with an older encoding rule. When the app sends a literal string into a strict function, the character set check fails right away.
Implicit conversions inside stored routines cause similar issues for backend teams. A stored routine retains the character set active when an admin created it. If that saved encoding conflicts with a modern function inside the routine, the call fails.
How to find and fix the failure in production
Start by reading the exact error text in your app logs. The message names both the broken function and the rejected character set. This tells you where to look in your query or schema.
Next, check the character set of the columns passed into that function. You can query the information schema with a read-only role to inspect column encodings. Check the session encoding variables for the app user as well.
Customer Support Access to Production + MySQL Access Governance: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
For a fast fix without changing tables, update the query itself. Tell the query to convert the string to a supported Unicode encoding before the function runs. This lets the query finish while keeping existing table data untouched.
For a permanent fix, align your table columns and app sessions on one modern Unicode character set. Test any column changes in a staging database first to check for index size limits. Update your app connection settings so new sessions send text in the right format.
Preventing character set mismatches across database teams
Standardize character set rules across all database instances to stop future errors. Set clear rules for table creation scripts so developers always pick supported Unicode formats. Review schema migrations before deployment to catch legacy encodings early.
Keep production access safe while engineers inspect and fix these encoding bugs. Developers should not need broad admin rights just to check column metadata. Grant scoped read roles and mask sensitive fields like emails or phone numbers in query results.
Track all ad-hoc queries run during an incident in a central log. When teams test string conversions against live tables, audit logs record every action. This keeps your data safe while engineers fix the broken queries.
Add wire guardrails and masking beside MySQL
Database grants and TLS setup decide who can reach MySQL. Even so, an open session can run broad updates or read raw personal data from allowed tables. In practice, hoop.dev sits inline in the wire protocol beside the database as a sidecar for your MySQL. On every production query an agent or engineer sends, hoop.dev decides to pass, mask, block, or escalate it for human review.
With hoop.dev MySQL support, guardrails refuse bad queries before they run or hold risky calls for approval, while data masking rewrites matched sensitive values in result rows in memory. Furthermore, hoop.dev holds SOC 2 Type II and generates evidence for GDPR, HIPAA, and PCI DSS programs. Read the docs and source on GitHub.
Frequently asked questions
What does SQLSTATE HY000 mean for mysql error 3987?
SQLSTATE HY000 is a general error code used by the database engine. You must read the specific error number 3987 to know it is a character set mismatch.
Can I fix this error without altering production tables?
Yes, you can convert the text encoding inside the query before calling the function. This fixes the error right away without running a table migration.
Why did this error start after a client driver update?
A driver update can change the default character set used when your app logs in. If the new default uses an unsupported encoding, strict database functions will reject the input.
Related guides
In this post