For MySQL, utf8 is not enough, you want utf8mb4

Someone entered 😨, the “fearful face emoticon”, in a forum on a website I run. But it didn’t display.

Here’s what I had to do to get it to work:

  • ALTER DATABASE dbname CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
  • ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
  • ALTER TABLE tablename MODIFY columnname COLUMNNAMEEXISTINGTYPE CHARACTER SET utf8mb4;
  • In my.conf:

    [client]
    default-character-set = utf8mb4

    [mysqld]
    collation-server = utf8mb4_unicode_ci
    init-connect=’SET NAMES utf8mb4′
    character-set-server = utf8mb4

Note that if you are converting from latin-1 not utf-8 you will need to convert columns to blob and then to utf8mb4 to correctly preserved already latin1-encoded special characters.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.