"Mysql" resolves insert data that appears incorrect string value: ' \xf0\x9f\x92\x8bti ... ' ERROR

Source: Internet
Author: User
Tags mysql version

Background: The user entered the form inside. Presence of the phone's own expression, when the insertion error

Incorrect string value: ' \xf0\x9f\x92\x8bti ... '

Error reason: When we set the MySQL encoding format in general Utf-8 format, is not supported with a four-byte string inserted.

Workaround:

1. Upgrade MySQL, then change the corresponding data type to UTF8MB4 type (MySQL version >= 5.5)

2. Four bytes of UTF-8 character filtered or converted to a custom type

Method 1: (Can not only change the name of the table encoding and ignore the field encoding, Pro-Test.) Two must be changed to be able)

Upgrade MySQL directly and change the corresponding field to UTF-8MB4

Method 2: (not tried, online search)

$str Preg_replace $str);  

Pan Wai: (Online search of information)

For MySQL 5.5, if the character set is not set, the default MySQL character set is the Latin1 Latin character set;

In order to unify the management and the application development convenience, the general will unify the operating system, the client, the database each aspect character set to utf8 the character set, namely can satisfy each kind of character application, but also can unify the character set, avoids each kind of garbled question.    but with the further development of various businesses, in addition to the individual language characters in each country, there will often be some emoji appearing in the application, and before MySQL 5.5, the UTF-8 encoding only supports 1-3 bytes, which supports the Unicode encoding area of this part of BMP Starting with MySQL 5.5, you can support 4 byte UTF encoded UTF8MB4, one character can support more character sets, and can support more emoji.   UTF8MB4 is compatible with UTF8 and can represent more characters than UTF8, which is a superset of the UTF8 character set. So now some new businesses, such as the ISO, will set the MySQL database's charset to UTF8MB4.   Today, when dealing with an application requirement, is confronted with the problem of applying all clients to the UTF8 character set, the MySQL database is also the UTF8 character set, but there is now a business need to use the MB4 part of the added character, which requires MySQL data to adjust the character set.   Of course the best way to adjust is the client, the MySQL database character set is modified to UTF8MB4, but such a large amount of modification, and if the client part is modified to UTF8, part of the UTF8MB4, it is prone to confusion. So the business needs the UTF8 character set of all the clients, still keep it as a unified utf8, only modify the MySQL database side, to ensure that the client connection UTF8 character set is connected to the data use, can be used as utf8mb4 characters.   After several tests, the configuration of the character set in MySQL database my.cnf has been modified to the following configuration: 
[client]   default-character-set=utf8mb4    [mysqld]  character-set-server = utf8mb4  Collation-server = utf8mb4_unicode_ci  init_connect= ' SET NAMES utf8mb4 '  skip  True    [mysql]  default-character-set = Utf8mb4  

"Mysql" resolves insert data that appears incorrect string value: ' \xf0\x9f\x92\x8bti ... ' ERROR

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.