Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

微信表情不能入库(mysql)

DB_ERROR: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation

这个提示指的是 什么跟什么的编码不统一了。

tips:后来发现是 框架连接数据的类,设置字符集没有成功导致的~


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

在 MySQL 内, 你的表和客户端编码都需要使用 utf8mb4 编码, 才可以解决 Emoji 表情符号的问题, 即:

  1. 你的表的字符集得是 utf8mb4 (不能是 utf8), 至于排序规则 (collation) 是 utf8mb4_bin 还是 utf8mb4_general_ci 等等都关系不大, collation 仅影响到排序
  2. 客户端的会话你可以显式用 set names utf8mb4 进行初始化

这个问题的原因是你的表在使用 utf8 字符集, 而 MySQL 中的 utf8 字符集实现不完整, 不支持 4 个字节的 utf8 标准的字符, 但是考虑到兼容性, 不能直接在 utf8 上改动(因为影响到预分配空间的大小问题), 所以他们后续出了 utf8mb4 的字符集来解决这个问题


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...