VillageSQL is a drop-in replacement for MySQL with extensions.
All examples in this guide work on VillageSQL. Install Now →
utf8mb4 — The Right Default
Always useutf8mb4. MySQL’s utf8 (without the mb4) is a 3-byte encoding that cannot store 4-byte Unicode characters — which includes emoji, many Chinese characters, and various symbols. utf8mb4 is the complete UTF-8 encoding.
utf8, migrating to utf8mb4 requires converting the database, tables, and columns.
Character set quick-reference
The cost column is about the work required to fix a wrong choice later, not the performance cost of the charset itself.
latin1 is the trap: it accepts any byte value without error, so bad data gets in quietly and surfaces only when you try to display or convert it.
Collations
The collation determines sort order and comparison behavior. Common choices:utf8mb4_0900_ai_ci is the default collation and the best general-purpose choice. It handles Unicode correctly, is case-insensitive (ci), and accent-insensitive (ai). Use utf8mb4_bin only when you need exact byte matching.
ci = case-insensitive, cs = case-sensitive, ai = accent-insensitive, as = accent-sensitive.
Setting Character Sets
At database creation:CONVERT TO changes every column in one statement. It rebuilds the table, so it takes time proportional to table size.
Checking Character Sets
SHOW CREATE TABLE that don’t show a charset are inheriting from the table default.
Connection Character Set
The connection character set controls the encoding MySQL expects from the client and uses for string literals. Always set it explicitly:utf8mb4, so explicit overrides are rarely needed.
Collation Effects on Queries
Collation affectsWHERE, ORDER BY, and uniqueness:
Converting from utf8 to utf8mb4
If your legacy database usesutf8 (3-byte), convert it:
utf8mb4 the default for new connections:
Frequently Asked Questions
Why does utf8 in MySQL not support emoji?
MySQL’s utf8 is a non-standard 3-byte subset of UTF-8 that predates the 4-byte Unicode extension. Emoji (and many other modern Unicode characters) require 4 bytes. utf8mb4 is the correct full implementation of UTF-8. The old utf8 alias exists for backward compatibility only — never use it for new schemas.
Does changing collation affect existing data?
Changing collation doesn’t change the stored bytes. It changes how those bytes are compared and sorted. However, unique indexes are enforced using the collation, so changing from_bin to _ci may reveal collisions (Alice and alice become equal) that must be resolved first.
Which collation should I use?
utf8mb4_0900_ai_ci for most use cases — it’s the default collation and handles Unicode well. Use utf8mb4_bin only when you need exact byte matching. Avoid utf8mb4_general_ci in new projects — it predates _0900_ai_ci and handles some Unicode edge cases incorrectly.
Troubleshooting
See also
- MySQL String Functions — string functions whose behavior depends on collation

