How to Fix MySQL Error 3721 (ER_INVALID_DEFAULT_UTF8MB4_COLLATION)

Published
Length
3 min read

Luis Felipe Dias

All posts

You get mysql error 3721 when you set a bad default collation for four-byte UTF-8 text. To fix this error, update your server setting to use one of the two allowed collations. Database engines use character sets and collations to store and sort text data. When a server or client session requests an unsupported default collation, the engine stops the query. It returns symbol ER_INVALID_DEFAULT_UTF8MB4_COLLATION under SQLSTATE HY000 to protect text sorting rules. What triggers mysql error 3721

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 3721 when you set a bad default collation for four-byte UTF-8 text. To fix this error, update your server setting to use one of the two allowed collations.

Database engines use character sets and collations to store and sort text data. When a server or client session requests an unsupported default collation, the engine stops the query. It returns symbol ER_INVALID_DEFAULT_UTF8MB4_COLLATION under SQLSTATE HY000 to protect text sorting rules.

What triggers mysql error 3721 in your database

The official message states that the default collation is invalid for the four-byte character set. The engine expects either utf8mb4_0900_ai_ci or utf8mb4_general_ci as the default setting. If a user or app supplies any other collation here, the server rejects the change.

This failure often happens during database upgrades or when teams migrate between cloud providers. Older apps might send legacy connection strings that try to set custom default rules. Some database drivers also run initialization queries right after they log in to the server.

Cluster replication can also break when primary and replica nodes use different server settings. If a primary node sends a session event with an unsupported collation, the replica halts. Your team must keep character set rules identical across every node in the cluster.

How to diagnose and fix the collation failure

Start by checking your server error logs and recent deployment changes to find the source. Look at the startup files and session variables that your app sends when connecting. You only need read access on system variables to find the broken setting.

Once you find the bad collation value, change it to utf8mb4_0900_ai_ci or utf8mb4_general_ci. Do not grant full admin rights to developers just to debug session variable errors. Instead, have a database admin review the change and apply it through your deployment pipeline.

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 specific table or column needs a custom sort order, set it directly there. You can define custom collations at the table or query level without changing the global default. This keeps the server default valid while still supporting special sorting rules for your app.

How to prevent collation errors across production teams

Many database outages happen when engineers run ad-hoc session changes in live databases. When someone tests a fix in production, a bad variable can break active app connections. Teams need clear guardrails around who can change server settings and run admin commands.

Standardize your connection templates so every app uses the same valid character set settings. Review database migration scripts in staging before anyone runs them against live data. You should also log every admin query to track when and why session settings change.

Keep production data safe during debugging by masking sensitive fields in query outputs. Data masking rewrites matched fields like emails, phone numbers, card numbers, and national IDs in results. This lets engineers check character encoding issues on real tables while protecting private customer records.

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 are the two valid collations for this MySQL setting?

The database engine only accepts utf8mb4_0900_ai_ci or utf8mb4_general_ci for this default collation setting. Any other collation name will trigger error code 3721 right away.

Can I still use other UTF-8 collations on my tables?

Yes, you can assign other valid collations directly to specific databases, tables, or columns. The restriction in error 3721 only applies to the default collation setting for utf8mb4.

Why did mysql error 3721 start happening after an upgrade?

Newer database versions enforce stricter checks on default character set and collation pairings. A startup script or driver setting that worked before may now fail validation during login.

The query runs. The emails stay hidden.