Search code examples
mysqlwordpressencodingcharacterutf8mb4

Wordpress site: Random Character Coding error


I have a Wordpress site which randomly shows an error like:

WordPress database error: [Incorrect string value: '\xF0\x9F\x92\x97\xF0\x9F...' for    column 'option_value' at row 1] UPDATE `wp_options` SET `option_value` = 'a:95:{

This is a placeholder site; the data was exported from the existing live using PhpMyAdmin into a .sql file. I suspect there is some kind of character encoding issues? I have exported by whatever the 'default may have been as well as UTF8. In the imported database I have tried both character encoding and collation as UTF8 (which it is currently) as well as 'Latin1 ISO8899 Western Europe' and 'utf_general_ci' as encoding and collation, respectively, but no luck.

I notice that the error happens when I go to the site after an interval.

What can I do? Thanks!


Solution

  • I’ve recently written a detailed guide on how to switch from MySQL’s utf8 to utf8mb4. If you follow the steps there, everything should work correctly. Here are direct links to each individual step in the process: