"Original" Easy to solve Chinese garbled problem (2)---Analysis to resolve MySQL insert mobile side emoticons error ' Incorrect string value: ' \xf0 ...

Source: Internet
Author: User

This blog focus on solving problems, if you do not know the character encoding, it is recommended to first look at "original" easy to understand the problem of Chinese garbled (1)---cross-platform garbled .

Of course, if only to solve this MySQL insertion error problem, this article is enough.

First, positioning errors

Locating errors is definitely a vital link. I suggest to have a problem patient analysis is better, after all, "not all the milk is called the special-Sue."

There may be a lot of problems causing the same problem, and others ' solutions may not suit them.

Let's see where the problem is, the error is as follows:

The discovery is indeed a coding error, 16-binary error hint (\xf0\x9f\x94\xa5\xe5\x8c ... Although it's quite clear, it doesn't hurt to look at the value of this field.

Look at this moment ' event_title ' What the devil is, as follows:

It turns out there is a special character '?? '. The source of this character is mobile, and now we chat without an expression to sell Meng can also be a friend? So a large number of emerging characters on the mobile side do require a change to the database.

So, what about the binary of this character? The following (first line):

Here we can basically locate the cause of this problem .

1, this character occupies three bytes.

2, according to the previous article on the UTF-8 encoding method, we know for UTF-8 three bytes of encoding, its format is 1110xxxx (e0-ef) 10yyyyyy 10zzzzzz. but this special character low 8 bit unexpectedly is 1111, obviously does not conform to the UTF-8 encoding rule, therefore MySQL does not support writes. (In fact, this is consistent with the initial error message)

Second, solve the problem

The problem is fixed, so it's time to find a way to solve it, and there are two options.

1, ah you good I am afraid of not yet, so trouble you do not put into storage. Therefore, the corresponding solution is to put the confusion before the storage of characters deleted.

2, Rub Lao Tzu Kung Fu number one, must see a pair of split. So the solution is to find out which MySQL version can support, update the version of MySQL.

Life can be capricious, but the choice needs to be serious. So according to their actual situation to choose. But generally choose 2 less, update database version is really a more involved problem.

Workaround:

For the 1 solution too much, a matter of opinion. I chose to use regular expressions to deal with this problem, because after all, it's not just this one character.

I use the "[^,。!]&\\pp|\\pz|\\ps" rule to match my own situation.

For 2, I checked the information and found that MySQL 5.6 and later expanded the support of UTF-8, and added the UTF8MB4 settings to the corresponding fields (thanks to the magic element reminders, the fear of misleading others), but through my experiment did not solve the problem .

You may need to add the UTF8_GENERAL_CI setting to the corresponding field . However, this setting I did not test, if you find MySQL which version and configuration can solve the problem trouble leave a message wow ~

The article concludes with a little explanation of this option (utf8_general_ci).

attached: utf8_unicode_ci and utf8_general_ci differences (from wiki)

There are multiple character sets in the database system MySQL, where Utf8_unicode_ci and utf8_general_ci are the most common, but utf8_general_ci support for some languages has some minor problems, and if acceptable, it's best to use utf8_ General_ci, because it's fast. Otherwise, use a more precise utf8_unicode_ci, but slower.

Reprint Please indicate the source, thank you ~ http://www.cnblogs.com/xiaoboCSer/p/4175861.html

"Original" Easy to solve Chinese garbled problem (2)---Analysis to resolve MySQL insert mobile side emoticons error ' Incorrect string value: ' \xf0 ...

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.