Let MySQL support emoji emoticons

Source: Internet
Author: User

Java get to the end of the delivery of emoji expression inserted after MySQL error message, errors are as follows

Java.sql.SQLException:Incorrect string value: ' \xf0\x9f\x92\x94 ' for column ' name ' at row 1 at com.mysql.jdbc.sqlerror.c Reatesqlexception (sqlerror.java:1073) at Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:3593) at Com.mysql.jdbc.MysqlIO.checkErrorPacket (mysqlio.java:3525) at Com.mysql.jdbc.MysqlIO.sendCommand (Mysqlio.java : 1986) at Com.mysql.jdbc.MysqlIO.sqlQueryDirect (mysqlio.java:2140) at Com.mysql.jdbc.ConnectionImpl.execSQL ( connectionimpl.java:2620) at Com.mysql.jdbc.StatementImpl.executeUpdate (statementimpl.java:1662) at Com.mysql.jdbc.StatementImpl.executeUpdate (statementimpl.java:1581)

The UTF-8 encoding can be two, three, and four bytes. The Emoju expression is 4 bytes, while MySQL UTF8 encodes up to 3 bytes, so data cannot be plugged in. The solution is to convert the MySQL encoding from UTF8 to UTF8MB4.

1: Modify MY.CNF

[Mysqld]

Character-set-server=utf8mb4

[MySQL]

Default-character-set=utf8mb4

Restart MySQL after modification


2: Command

ALTER TABLE [table_name] CONVERT to CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

Let MySQL support emoji emoticons

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.