MySQL throws Incorrect string value error

It’s the character at the end of the tweet that’s causing the problem.

It looks like an ’emoji’ character aka japanese smiley face but it’s not displaying for me in either Chrome or Safari.

There are known issues storing 4byte utf characters in some versions of MySQL. Apparently you must use utf8mb4 to represent 4 byte UTF characters, as the normal utf8 character set can only represent characters up to 3 bytes in length and so can’t store character which are outside of the Basic Multilingual Plane

http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html

Which is news to me as it basically means that the utf8 datatype in MySQL isn’t really proper utf8.

There are suggestions of how to handle this here
How to insert utf-8 mb4 character(emoji in ios5) in mysql? including:

“Also make sure your app layer sets its database connections’ character set to utf8mb4. Double-check this is actually happening – if you’re running an older version of your chosen framework’s mysql client library, it may not have been compiled with utf8mb4 support and it won’t set the charset properly. If not, you may have to update it or compile it yourself”

If you’re using Connector/J you need to set character_set_server=utf8mb4 in the connection config.

All your character sets should be utf8mb4, which you may have tried but aren’t currently set.

Leave a Comment

tech