All Products
Search
Document Center

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

Last Updated:Mar 28, 2026

When you insert emoji data into an ApsaraDB RDS for MySQL instance, you may see one of these errors:

  • error code [1366]; Incorrect string value: 'xx'

  • General error: 3988 Conversion from collation utf8mb3_general_ci into utf8mb4_general_ci impossible for parameter

These errors occur because MySQL's utf8 character set supports a maximum of 3 bytes per character, but storing an emoji requires 4 bytes. The solution is to switch to utf8mb4, which is a strict superset of utf8 that supports all Unicode characters, including emojis.

utf8mb4 must be configured at every layer of your stack: the client, the database connection layer, and the RDS instance.

Compatibility requirements

To store emojis, configure utf8mb4 at each of the following components:

Client

Configure the client to use utf8mb4 for output strings. The exact method depends on your application framework or library.

Database connection layer

For Java applications using JDBC (Java Database Connectivity):

  • Use MySQL Connector/J version 5.1.13 or later.

  • Do not set the characterEncoding parameter in your JDBC connection string.

Omitting characterEncoding lets MySQL Connector/J autodetect the character set from the server. If you set characterEncoding explicitly, it overrides autodetection and can prevent utf8mb4 from being applied correctly.

RDS instance

Configure utf8mb4 at the instance level in the ApsaraDB RDS console, then apply it to any existing database objects.

Instance parameter

Configure the instance parameters and set:

character_set_server = utf8mb4

Database and table objects

For existing databases and tables, run the following SQL statements:

ALTER DATABASE db_name CHARACTER SET utf8mb4;
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4;

Character set change priority

If you need to change the character set for specific objects rather than the entire instance, apply the change at the appropriate level:

LevelWhen to use
Instance (character_set_server)All new databases on the instance should default to utf8mb4
DatabaseOnly specific databases need utf8mb4; leave others unchanged
TableOnly specific tables in a database need utf8mb4
FieldOnly specific columns need utf8mb4
Note

After switching from utf8 to utf8mb4:

  • Data compatibility is not affected.

  • New emoji data can be stored.

  • Estimated data storage is increased.