All Products
Search
Document Center

:How do I use the utf8mb4 character set to store emojis in an ApsaraDB RDS for MySQL instance?

Last Updated:Nov 30, 2023

When I store emojis in an ApsaraDB RDS for MySQL instance, the "error code [1366]; Incorrect string value: 'xx'" error message is displayed. The cause is that a character in the UTF-8 character set occupies up to 3 bytes. However, an emoji occupies 4 bytes. In this case, you can use the utf8mb4 character set to store emojis in RDS for MySQL.

Basic rules

To store emojis in an RDS instance, you must use the utf8mb4 character set for the client, the sessions on the instance, and the instance.

  • Client: Make sure that the client uses the utf8mb4 character set for the output strings.

  • Sessions on the RDS instance: Make sure that the sessions support the utf8mb4 character set. For example, you must use MySQL Connector/J 5.1.13 or later for JDBC connections, and we recommend that you do not configure the characterEncoding parameter for the connections.

  • RDS instance: In the ApsaraDB RDS console, you need to set the character_set_server parameter to utf8mb4 and make sure that databases and tables use the utf8mb4 character set.

Modify character sets

If the operations described in the preceding basic rules are not complete, you can modify the character set based on the instructions in Character set description for ApsaraDB RDS for MySQL.

Note

If you change the character set from UTF-8 to utf8mb4, the quality of new data is not compromised and the existing data is not affected. However, data storage usage is increased.