When a WordPress database moves from an older host to a current cPanel server, charset and collation often don’t match. Emojis stop rendering. Accented characters get replaced with question marks or ?s. Search returns no results for queries that worked yesterday. The cause is utf8 (which in MySQL means 3-byte UTF-8, not real UTF-8) vs utf8mb4 (4-byte, actual UTF-8 including emoji).
What’s happening
MySQL’s utf8 predates the rest of the world adopting full UTF-8. It supports characters in the Basic Multilingual Plane only — three bytes per character maximum. Emojis, some Asian scripts, and some mathematical symbols need four bytes; utf8 can’t store them. MySQL 5.5+ added utf8mb4, which is real UTF-8. WordPress 4.2+ defaults to utf8mb4. A site that originally lived on a MySQL 5.1 host with utf8 tables and then got migrated retains the original charset until you convert it.
How to verify
Check the database, server, and connection charsets:
wp db query "SELECT default_character_set_name FROM information_schema.SCHEMATA WHERE schema_name = DATABASE()"
wp db query "SHOW TABLE STATUS" | grep -i collation
wp db query "SHOW VARIABLES LIKE 'character_set_%'"
For WordPress’s view:
wp config get DB_CHARSET
wp config get DB_COLLATE
If the database charset is utf8 but DB_CHARSET says utf8mb4, WordPress is asking for 4-byte UTF-8 from a 3-byte UTF-8 database — and writes silently truncate at the first 4-byte character.
The fix
-
Decide the target. Modern WordPress on modern MySQL:
utf8mb4withutf8mb4_unicode_520_ci(orutf8mb4_0900_ai_cion MySQL 8.0+). Don’t go toutf8mb4_general_ci— its sorting is wrong for several languages. -
Take a backup first. Always, but especially before a charset conversion that touches every row:
wp db export ~/pre-charset-backup-$(date +%F).sql -
Update
wp-config.php:define( 'DB_CHARSET', 'utf8mb4' ); define( 'DB_COLLATE', '' );An empty
DB_COLLATElets WordPress use the database default, which is what you want. -
Convert each table. The script:
for table in $(wp db tables --format=csv | tr ',' '\n'); do wp db query "ALTER TABLE $table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_520_ci" doneOn large tables this rebuilds the table — plan for a maintenance window proportional to the table size. The
wp_postmetatable on a busy WooCommerce site can take an hour. -
Some indexes hit MySQL’s 767-byte limit when converting from
utf8toutf8mb4because the same character count now requires more bytes. Symptom:ALTER TABLEfails with “Specified key was too long”. Fix by enablinginnodb_large_prefix(default on MySQL 5.7.7+) andinnodb_file_format=Barracuda, then retry. Older WordPress versions had aDROP INDEXstep they recommended; on recent MySQL/MariaDB the index limit is rarely hit. -
After conversion, verify:
wp db query "SELECT TABLE_NAME, TABLE_COLLATION FROM information_schema.TABLES WHERE TABLE_SCHEMA = DATABASE()" | headEvery table should now show the new collation. Try writing an emoji to a post, save, refresh — should display correctly.
-
If converting an old
utf8database where mixed encoding rot has already happened (some rows have correct UTF-8, some have double-encoded characters from past migrations), straight conversion preserves the rot. In that case you need to dump, run a re-encoding script (iconvor a one-off PHP), then import. That’s the more complex path; do it only after you’ve confirmed the data is actually mis-encoded by inspecting raw bytes:wp db query "SELECT HEX(post_title) FROM wp_posts WHERE post_title LIKE '%é%' LIMIT 5"
For environments where this is part of a migration workflow, Stack Harbor handles charset conversion as part of migration.
Stack Harbor operates production WordPress at scale — see Enterprise WordPress for the managed model, or book a WordPress consult for a written read of your current shape.