PHP and MySQL

MySQL utf8mb4 and collation: a practical guide

Choose utf8mb4, understand comparison rules and migrate character data without silently changing semantics.

By AppLaunch Editorial · Reviewed 2026-08-25

Direct answer

In modern MySQL, utf8 is a deprecated alias for the three-byte utf8mb3 character set; utf8mb4 stores full Unicode. Collation determines sorting and equality rules, so choose it deliberately and test unique indexes before conversion.

What this means in plain English

A character set decides which text MySQL can store. utf8mb4 supports full Unicode, including emoji and many characters that MySQL’s older utf8 name cannot safely hold. A collation decides how stored text compares and sorts.

Changing collation can change whether two values count as equal. Test unique usernames, codes and indexes on a copy before converting a live table, because previously different values may collide under new comparison rules.

Why use utf8mb4 instead of utf8?

Character setWhich code points can be stored
CollationHow strings compare and sort
Migration riskPreviously distinct values may compare equal

A simple example

A table using old utf8 cannot store a four-byte emoji in a profile name. Moving to utf8mb4 fixes the storage range, but the team first tests its case-insensitive unique username index to ensure no two existing names become equal.

What to do, step by step

  1. 1. Inspect server, database, table and column settings.

    Start here before buying anything or changing several settings at once. It gives you a clear starting point based on character set: which code points can be stored. Write the result down so you can compare it later.

  2. 2. Choose a collation matching language and case needs.

    Use the same files, versions and settings that the real project will use. A quick test with an empty or different setup can look successful while completely missing the problem you are trying to solve.

  3. 3. Test duplicate and index impact on a copy.

    Try the busiest realistic situation, not the easiest one. Include the people, data, traffic or background work you genuinely expect, then watch for slowdowns and errors rather than relying on a single headline number.

  4. 4. Set client connection character set explicitly.

    Finish by checking the result against migration risk: previously distinct values may compare equal. Keep the old setting or release available until you know the change works and can be reversed safely.

One more useful tip

Set the application connection to utf8mb4 too. A utf8mb4 table cannot help if the client sends text through the wrong connection character set.

Common mistakes and how to avoid them

Assuming utf8 means full UTF-8 in MySQL.

This gives a misleading or unsafe result because it leaves out character set. A better approach is to inspect server, database, table and column settings, then check the result before making the change permanent.

Converting production without checking indexes.

This gives a misleading or unsafe result because it leaves out collation. A better approach is to choose a collation matching language and case needs, then check the result before making the change permanent.

Mixing connection and table encodings.

This gives a misleading or unsafe result because it leaves out migration risk. A better approach is to test duplicate and index impact on a copy, then check the result before making the change permanent.

Words explained

MySQL
A database that stores structured information such as accounts, orders, settings and website content.
index
An extra structure that helps MySQL find rows faster, similar to an index in a book. Indexes also use space and make writes do more work.
collation
The rules MySQL uses to compare and sort text, including whether upper- and lower-case letters are treated as equal.
migration
A planned change to database structure or stored data when a new application version is released.

Quick checklist

  • Inspect server, database, table and column settings.
  • Choose a collation matching language and case needs.
  • Test duplicate and index impact on a copy.
  • Set client connection character set explicitly.

Common questions

What is the simple answer?

In modern MySQL, utf8 is a deprecated alias for the three-byte utf8mb3 character set; utf8mb4 stores full Unicode. Collation determines sorting and equality rules, so choose it deliberately and test unique indexes before conversion.

What should I check first?

Start with character set: which code points can be stored. That is usually more useful than choosing from a marketing label or copying somebody else’s setting.

How can I make the change safely?

Inspect server, database, table and column settings. Then change one thing at a time, keep a backup or old version, and use the same real-world test after each change.

What is the easiest mistake to avoid?

Assuming utf8 means full UTF-8 in MySQL. Avoiding that one mistake makes the rest of the comparison much more trustworthy.

Primary sources

  1. MySQL character sets and collations — Oracle