Home  >  Article  >  Database  >  MySQL抛出Incorrect string value异常分析_MySQL

MySQL抛出Incorrect string value异常分析_MySQL

WBOY
WBOYOriginal
2016-06-01 13:23:261083browse

bitsCN.com 之前还以为从上至下统一用上UTF-8就高枕无忧了,哪知道今天在抓取新浪微博的数据的时候还是遇到字符的异常。
从新浪微博抓到的数据在入库的时候抛出异常:
Incorrect string value: '/xF0/x90/x8D/x83/xF0/x90...'
发现导致异常的字符不是繁体而是某种佛经文字。。。额滴神。。。但是按道理UTF-8应该能支持才对啊,他不是万能的么?
原来问题出在mysql上,mysql如果设置编码集为utf8那么它最多只能支持到3个字节的UTF-8编码,而4个字节的UTF-8字符还是存在的,这样一来如果你建表的时候用的utf8字符集出异常就理所当然了。
解决方法很简单,修改字段或者表的字符集为utf8mb4。
比较蛋疼的是,字符集utf8mb4在mysql 5.5.3之后才支持。bitsCN.com

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn