Help Center/ Relational Database Service/ FAQs/ Database Parameter Modification/ How Do I Use the utf8mb4 Character Set to Store Emojis in an RDS for MySQL DB Instance?
Updated on 2024-10-22 GMT+08:00

How Do I Use the utf8mb4 Character Set to Store Emojis in an RDS for MySQL DB Instance?

To store emojis in an RDS for MySQL DB instance, ensure that:

  • The client outputs the utf8mb4 character set.
  • The connection supports the utf8mb4 character set. If you want to use a JDBC connection, download MySQL Connector/J 5.1.13 or a later version and leave characterEncoding undefined for the JDBC connection string.
  • Configure the RDS DB instance as follows:
    • Setting character_set_server to utf8mb4

      1. Log in to the management console.
      2. Click in the upper left corner and select a region.
      3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
      4. On the Instances page, click the instance name.
      5. In the navigation pane on the left, choose Parameters. On the Parameters tab page, locate character_set_server and change its value to utf8mb4.
      6. Click Save. In the displayed dialog box, click Yes.
    • Selecting utf8mb4 for the character set of a database
      1. Log in to the management console.
      2. Click in the upper left corner and select a region.
      3. Click in the upper left corner of the page and choose Databases > Relational Database Service.
      4. On the Instances page, click the instance name.
      5. On the Databases page, click Create Database. In the displayed dialog box, enter a database name and remarks, select the character set utf8mb4, and authorize permissions for users. Then, click OK.
        Figure 1 Creating a database
    • Setting the character set of a table to utf8mb4

FAQs

If you have set characterEncoding to utf8 for the JDBC connection string, or the emoji data cannot be inserted properly after you have performed the above operations, you are advised to set the connection character set to utf8mb4 as follows:

String query = "set names utf8mb4";
stat.execute(query);