Article

MySQL utf8mb4 Migration for PHP Apps

Understand MySQL utf8 vs utf8mb4, plan table conversions, fix connection charset, and avoid mojibake and historic index-length surprises.

In MySQL, the historical charset named utf8 (also called utf8mb3) stores a maximum of three bytes per character and cannot represent many Unicode characters, including most emoji. utf8mb4 is the four-byte UTF-8 charset you want for new and modernized schemas. PHP must also negotiate utf8mb4 on the connection or the database still misinterprets strings.

LEGACY — incomplete UTF-8
MODERN — utf8mb4 end-to-end

Conversion planning

  1. Backup the database; restore the backup on a staging instance first.
  2. Inventory columns, indexes, and maximum indexed prefix lengths—older MySQL versions had tighter index byte limits with utf8mb4.
  3. Convert tables/columns in a maintenance window; rebuild indexes as needed.
  4. Deploy PHP DSN/charset changes with the schema change.
  5. Test with strings that previously failed (emoji, uncommon scripts) and watch for mojibake.

Parent guide: Database modernization. Confirm connection settings with Environment Compare and Config Diff.

Related reading