This post is mostly here so that I can test the comment feature in production. I just updated my
blog_comment table to use the
utf8mb4 character set, which means that it can now support Emoji characters:
ALTER TABLE `blog_comment` MODIFY COLUMN `content` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, MODIFY COLUMN `content_markdown` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL ;
From what I understand, the
utf8mb4 character set enables support for characters in the Astral Plane, which is where many (but not all) emoji characters live. Specifically, it supports Emjoi that require 4-bytes to encode.
On it's own,
utf8mb4 doesn't enable Emoji support in my running MySQL server. I also had to tell the
INSERT statement to use the appropriate character set:
SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci; INSERT INTO blog_comment ( content, content_markdown, -- .... truncated for demo ....
I believe that there is a way to configure the MySQL server to use those settings by default; however, that's beyond my experience at this point. So, rather than go down that rabbit-hole this morning, I'm just using
SET NAMES, which I know works.
And now, hopefully, I'll be able to add Emoji in the comments below!
Want to use code from this post? Check out the license.