Inserting Chinese characters into MySQL (Emoji) appears incorrect string value

Source: Internet
Author: User

When the crawler inserted data into MySQL, it found an error "" "Incorrect String Value: ' \xf0\x9f" ", the problem is because UTF-8 can be two, three, four bytes, emoji expression or some special character is 4 bytes, So the content crawled from the Web page may contain emoticons, while MySQL's UTF8 encoding is up to 3 bytes, so data cannot be plugged in. The solution is as follows:

Find my.cnf under/etc, modify as follows:

[Mysqld]

Character-set-server=utf8mb4

[MySQL]

Default-character-set=utf8mb4

Restart MySQL after modification

The already built table is also converted to UTFMB4:

Change database encoding: Alter DB caitu99 CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci ;

ALTER TABLE table_name convert to Character set UTF8MB4 collate utf8mb4_bin;

Inserting Chinese characters into MySQL (Emoji) appears incorrect string value

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.