Search code examples
mysqlutf-8emojiutf8mb4

MySQL returning multiple results for a single emoji


I'm observing some strange MySQL behavior for VARCHAR fields that contain a single emoji. The connection, database and column are all utf8mb4 encoding and collation.

There's a table called categories with id and title fields. There's three rows, with titles of 💳, 🍌 and 🎁.

When I run a query looking for a row with the title 💳, I get all the other rows with single emojis as well, as if MySQL is treating them as the same characters.

Query for credit card emoji returning all other single emoji rows

The expected behaviour should be that only the row with 💳 is returned.


Solution

  • You need the collation utf8mb4_unicode_520_ci; the older collations treat Emoji as equal.