MySQL throws an incorrect string value exception Analysis
Source: Internet
Author: User
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.
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.