Mysql emoji characters

Disclaimer: This article is an original article by the blogger and may not be reproduced without the permission of the blogger.

In the past, when creating MySQL tables, the default encoding was utf8, not always. Recently, I was writing a page for a mobile phone. During the test, I found that if I entered Emoji characters in the input box, an error will be reported when I save it into the database:

Error 1366: Incorrect string value: '\xF0\x9F\x91\xBD\xF0\x9F ...' for column 'content'


Google says that MySQL's utf8 is not real UTF8, it can only contain three bytes of unicode, and 4 bytes will report an error. To solve this always use the utf8mb4 encoding. But I still can't save Emoji characters after I change the CHARSET of the table and column to utf8mb4.

It turns out that I have to modify the character-set-server of mysqld in my.cnf, change it to utf8mb4, and then restart mysqld to save Emoji characters.

[mysqld]
character-set-server = utf8mb4

 

Therefore, it is recommended that you set the default character set to utf8mb4 when designing tables in the future, because Emoji characters are very popular now, and users will inevitably enter Emoji characters in the browser.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326883716&siteId=291194637