Converting a MySQL database to UTF-8 (utf8mb4)
utf8mb4 is the character set modern apps use. It stores every language and symbol, including emoji. Older databases often use latin1 or the older utf8 (also called utf8mb3), which can’t store emoji and some characters. You may see:
- Question marks (
????) in place of emoji or some characters. - Errors such as “Incorrect string value” when saving content.
- WordPress warnings about the database character set.
This guide converts a database to utf8mb4 with the utf8mb4_unicode_ci collation.
Check the current character set
Section titled “Check the current character set”- In cPanel, open phpMyAdmin and click your database on the left.
- The Collation column shows each table’s collation. Anything starting with
latin1_orutf8_(notutf8mb4_) needs converting.
Convert in phpMyAdmin
Section titled “Convert in phpMyAdmin”- Click your database on the left, then the Operations tab.
- Under Collation, choose
utf8mb4_unicode_ci. - Tick Change all tables collations and Change all tables columns collations.
- Click Go.
This changes the database default and converts every table and text column.
Convert with SQL
Section titled “Convert with SQL”To convert tables one at a time, click your database, open the SQL tab and run, for each table:
ALTER DATABASE your_database CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;ALTER TABLE your_table CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;To create the commands for every table at once, run this, then copy the results into the SQL tab and run them:
SELECT CONCAT('ALTER TABLE `', table_name, '` CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;')FROM information_schema.tablesWHERE table_schema = 'your_database' AND table_type = 'BASE TABLE';After converting
Section titled “After converting”- Tell your app to use utf8mb4. In WordPress, check
wp-config.phphasdefine( 'DB_CHARSET', 'utf8mb4' );. In PHP code, connect withcharset=utf8mb4(PDO) or$mysqli->set_charset('utf8mb4'). See Specifying the MySQL character set in PHP. - Check your website. Look at pages with accents, other languages and symbols.
If text already looks wrong
Section titled “If text already looks wrong”If text already showed odd characters such as é instead of é before you converted, the data was saved with the wrong character set (double-encoded). Converting won’t fix this by itself and can make it worse. Restore your backup and contact support, and we’ll help you fix it.
Related articles
Section titled “Related articles”Was this page helpful?
Thanks for your feedback.