Skip to content

Emojis in a MySQL database

A while back, I’ve had issues when user input contained an emoji: the database field would then cut after (and including) the first emoji). My table seemed to be configured properly for Unicode though, so that was a bit puzzling.

It turned out that “utf8“, in MySQL/MariaDB language, doesn’t actually mean the real, proper UTF-8: it contains a MySQL-specific limitation preventing use of characters numbered above 0xFFFD (source, with also a comparison between utf8mb4_unicode_ci and utf8mb4_general_ci). So you’ll want to use utf8mb4, which is the real deal and will store emojis without issue.
The good news is, if you already have an utf8 database or table, the migration may be as easy as just switching the column types (still you should make a backup first, just to be safe), at least for me it was. You might want to have a look at this first, though: How to support full Unicode in MySQL databases.

While looking into this, I also found some stuff about utf32. Not sure if I’ll ever use it but here it is for bookmarking purpose.

Sorry that was once again a brief post, I’m cleaning up my tab groups because after Firefox decided to kill the feature, they now also killed the extension that tried to continue the feature… Thanks again Mozilla! 😡

Posted in web development.

0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

Some HTML is OK

or, reply to this post via trackback.

Please solve the CAPTCHA below in order to fight spamWordPress CAPTCHA