How Do I Use the utf8mb4 Character Set to Store Emojis in a GaussDB(for MySQL) Instance?
To store emoji in a GaussDB(for MySQL) 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 instance as follows:
- Setting character_set_server to utf8mb4
- Log in to the management console.
- Click in the upper left corner and select a region and a project.
- Click in the upper left corner of the page, choose .
- On the Instances page, click the instance name.
- In the navigation pane on the left, choose Parameters. On the Parameters tab page, locate character_set_server and change its value to utf8mb4.
- Click Save. In the displayed dialog box, click Yes.
- Selecting utf8mb4 for database character set
- On the Instances page, locate the instance and click Log In in the Operation column.
Alternatively, on the Instances page, click the instance name to go to the Basic Information page. Click Log In in the upper right corner of the page.
- On the displayed login page, enter the correct username and password and click Log In.
- On the Databases page, click Create Database. In the displayed dialog box, enter a database name, select the character set utf8mb4, and authorize database permissions for users. Then, click OK.
Figure 1 Creating a database
- On the Instances page, locate the instance and click Log In in the Operation column.
- Setting the character set of the table to utf8mb4
- Setting character_set_server 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);
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot