In MySQL, never use “utf8”. Use “utf8mb4”

In MySQL, never use “utf8”. Use “utf8mb4”

Adam Hooper

Today’s bug: I tried to store a UTF-8 string in a MariaDB “utf8”-encoded database, and Rails raised a bizarre error:

Incorrect string value: ‘xF0x9Fx98x83 

NOW WITH OVER +8500 USERS. people can Join Knowasiak for free. Sign up on
Read More

Leave a Reply

2 thoughts on “In MySQL, never use “utf8”. Use “utf8mb4”

  1. Aditya avatar

    This is also a security vulnerability because MySQL/MariaDB silently truncate strings at the first invalid character. This can result in data manipulation attacks where a higher level layer validates the complete input as UTF-8 for insertion into the DB, but the database only stores half the string.

  2. Aditya avatar

    > Database systems have subtle bugs and oddities, and you can avoid a lot of bugs by avoiding database systems.

    Wat? That is… not a great takeaway from this experience. "Oh, this library had bug reported in it! I know, that means I should just write my own, because clearly they're all buggy and my software is always perfect."