6

My database, tables, fields all are using utf8mb4. I can store well emoji symbols into some fields. Now I try to query such as:

SELECT * FROM user WHERE name='😀😇😈😉'

Amazing, the result are records with field names different such as '😀😃😇😉'

Looks like mysql matches emoji strings by their lengths but not contents.

Any idea to fix that problem? Many thanks.

4
  • This might help you: stackoverflow.com/questions/7814293/… Commented Jun 5, 2015 at 3:54
  • Thanks Stuart for very quick reply. My problem is quite different. I can store, browse and extract very well all strings with emoji symbols. Only problem of matching them when querying. Commented Jun 5, 2015 at 4:13
  • same situation here. Commented Feb 18, 2016 at 3:42
  • May have something to do with the upper/lower case algorithm (search 'A' and 'a' gives same rows). Commented Feb 18, 2016 at 4:07

3 Answers 3

2

Just did this command to my table:

ALTER TABLE tablename CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

that's all. the result is correct then.

Sign up to request clarification or add additional context in comments.

Comments

1

Try this:

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

Comments

0

What is the collation order on your table? Since you are using utf8mb4 it should be utf8mb4_unicode_ci. Anything else and you are likely to get the problem you are seeing - worse you might even get multiple records coming back.

To set the collation order use:

ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;

1 Comment

I have the same problem as the OP, and I have collation_connection, collation_database, and collation_server set to utf8mb4_unicode_ci. SELECT queries appear to indeed only match the number of emoji, and not the actual content (which is odd, to say the least).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.