Z
Z
Zaur Abdulgalimov2016-09-22 11:30:47
MySQL
Zaur Abdulgalimov, 2016-09-22 11:30:47

Why can't MySQL store a string with emoji characters?

Good afternoon.
There is a MySQL database with utf8mb4 encoding. I am writing an application in JAVA + Hibernate, immediately after creating the SessionFactory I write the following code (I found such an example somewhere on the net):

NativeQuery query = createNativeQuery("SET NAMES 'utf8mb4'");
query.executeUpdate();

And everything seems to be fine, lines with emoji characters are saved to the database and read normally.
But sometimes, quite rarely, I see the following error in the logs:
Incorrect string value: '\xF0\x9F\x87\xA9\xF0\x9F...' for column 'name' at row 1

The problem is reproduced with different emoji characters, not necessarily what I wrote above. Moreover, if you try to repeat the entry to the database with exactly the same string, everything works fine, and therefore it is not possible to debug this error.
Who knows help to understand.
Thank you.
PS I have learned to reproduce this problem. It remains to figure out how to overcome it :(

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2016-09-22
@SagePtr

I can assume that they forgot to put utf8mb4 in the encoding of some field

E
Eugene Ray, 2016-09-22
@firezhek

Perhaps the problem is the size of the line, try writing to Blob

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question