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
- Backup the database; restore the backup on a staging instance first.
- Inventory columns, indexes, and maximum indexed prefix lengths—older MySQL versions had tighter index byte limits with utf8mb4.
- Convert tables/columns in a maintenance window; rebuild indexes as needed.
- Deploy PHP DSN/charset changes with the schema change.
- 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
- Composer Modernization Center Add Composer to legacy PHP projects, migrate includes to autoloading, set platform constraints, and replace a…
- PHP 5 to Modern PHP: Complete Incremental Migration Guide A deep, production-minded path from PHP 5.x codebases to supported PHP 8.x: removed extensions, charset, PDO,…
- PHP Security Modernization for Legacy Applications Upgrade inherited PHP security practices: prepared statements, password hashing, sessions, CSRF, XSS escaping…
- PHP 7 to PHP 8 Migration Guide Deep guide to PHP 8.0 breaking changes that matter for PHP 7 applications, with upgrade tactics through suppo…
- Inheriting a Legacy PHP Application A first-30-days playbook for developers handed an unfamiliar PHP codebase: runtime truth, risk triage, and sa…