MySQL throws an Incorrectstringvalue exception Analysis

Source: Internet
Author: User
From the top to the bottom of the unified use of UTF-8 on the rest of the peace of mind, today still encounter character exceptions, this article will introduce the solution

From the top to the bottom of the unified use of UTF-8 on the rest of the peace of mind, today still encounter character exceptions, this article will introduce the solution

Previously thought from top to bottom unified use of UTF-8 on the rest of the peace of mind, which knows today in the capture of Sina Weibo data or encounter character exceptions.
An exception is thrown when the data captured from Sina Weibo is stored in the database:
Incorrect string value: '\ xF0 \ x90 \ x8D \ x83 \ xF0 \ x90 ...'
It is found that the characters that cause exceptions are not traditional Chinese characters but some Buddhist scriptures... Artifact... But according to the principle UTF-8 should be able to support only right, he is not omnipotent?
The original problem lies in mysql, mysql if set encoding set to utf8 so it can only support up to 3 bytes of UTF-8 encoding, and 4 bytes of UTF-8 characters still exist, in this way, if you use the utf8 character set when creating a table, it is a matter of course.
The solution is simple. Modify the character set of a field or table to utf8mb4.
However, utf8mb4 is supported only after mysql 5.5.3.

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.