Error 1267 Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT

版权声明:如若转载,请联系作者。 https://blog.csdn.net/liu16659/article/details/82937779

Mysql 报错: `Error 1267 Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation ‘=’

1.问题

mysql字符集不匹配导致比较时出错。
这种问题可能出现在Mysql函数,存储过程运行时

2.原因

使用的mysql的字符集与表中字段的字符集不一致。
这里的utf8mb4_unicode_ci和utf8mb4_general_ci是两种字符集排序方式。【其中的c指的就是Collation:排序规则

3.解决方法

  • 在使用的varchar 类型字段中添加字符排序方式:select * from user where mobile = in_mobile COLLATE utf8_unicode_ci;
  • 或者直接修改my.cnf文件,在[mysqld]中添加默认的字符集排序方式
[mysqld]
character-set-server=utf8
collation-server=utf8mb4_general_ci[###或者是utf8mb4_unicode_ci]

参考链接

猜你喜欢

转载自blog.csdn.net/liu16659/article/details/82937779
今日推荐