Home > Database > Mysql Tutorial > mysql插入Emoji表情报错_MySQL

mysql插入Emoji表情报错_MySQL

WBOY
Release: 2016-06-01 13:01:52
Original
809 people have browsed it

今天做的了个获取微信粉丝的功能,发现将昵称插入数据库报错.长度肯定是够的

Incorrect string value: '\xF0\x9F\x98\x84\xF0\x9F
Copy after login
找了点资料发现UTF-8编码有可能是两个、三个、四个字节。Emoji表情或者某些特殊字符是4个字节,而Mysql的utf8编码最多3个字节,所以数据插不进去。

网上解决方案都是

修改mysql配置

1.在mysql的安装目录下找到my.ini,作如下修改:
[mysqld]
character-set-server=utf8mb4
[mysql]
default-character-set=utf8mb4

2 重启

net stop mysql
net start mysql

3 修改表

ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;

我只做了第三步就解决我的问题了,现将其记录下来

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template