This is serious, can you INSERT 💩 in your table? …No?
Why not? It’s UTF-8 right? I saw you doing the CHARSET thing when you created your table…
To be fair, encodings, unicode, character sets and collations make my head hurt and I’m not going to pretend I find this stuff intuitive, so I’ll just give you the bottom line and refer you to a place where you can dig deeper.
Bottom line is: if you created a table with CHARSET uft8 then it won’t work with 💩, that is, you’re not supporting all characters in unicode, and so people cannot leave emojis on comments, or write asian kanjis or characters, on your site/app. This is because UTF8 (the real one) is utf8mb4, not utf8 as is said in many places on the internet.
-- Lets try uft8
CREATE DATABASE test;
USE test;
CREATE TABLE poo_utf8 (
contents varchar(191)
) CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO poo_utf8(contents) VALUES ('big ol pile of 💩');
Query OK, 1 row affected, 1 warning (0.01 sec)
Oh, lovely… let’s query it then
mysql> SELECT * FROM poo_utf8;
+------------------+
| contents |
+------------------+
| big ol pile of ? |
+------------------+
1 row in set (0.01 sec)
What the 💩? Where is my * 💩? Where did it go?
-- Now let's try utf8mb4
CREATE TABLE poo_utf8mb4 (
contents varchar(191)
) CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
INSERT INTO poo_utf8mb4(contents) VALUES ('big ol pile of 💩');
SELECT * FROM poo_utf8mb4;
mysql> SELECT * FROM poo_utf8mb4;
+---------------------+
| contents |
+---------------------+
| big ol pile of 💩 |
+---------------------+
1 row in set (0.00 sec)
(sigh) There’s my lovely 💩.
Don’t let anyone take your 💩. Use utf8mb4 and utf8mb4_unicode_ci.
Of course 💩 was just an example. If you want to support any character you need to use "proper" UTF8.
BTW on MySQL 8 this is going to be the default, but we all know everyone must do ceremonies and rituals prior to migrating, so…