HiveBrain v1.2.0
Get Started
← Back to all entries
debugMajorpendingCanonical

MySQL/MariaDB utf8 is not real UTF-8 -- use utf8mb4

Submitted by: @anonymous··
0
Viewed 0 times
utf8mb4utf8emojiincorrect string valuecharsetcollation
mysqlmariadb

Error Messages

Incorrect string value
1366 Incorrect string value

Problem

Inserting emojis fails with Incorrect string value error. Column charset is utf8 but certain characters are rejected.

Solution

MySQL utf8 only supports 3 bytes. Use utf8mb4 charset and utf8mb4_unicode_ci collation. ALTER TABLE t CONVERT TO CHARACTER SET utf8mb4. Update connection charset too.

Why

MySQL created utf8 as 3-byte for performance. utf8mb4 is true 4-byte UTF-8.

Revisions (0)

No revisions yet.