ILLEGAL MIX OF COLLATIONS (UTF8MB4_0900_AI_CI,IMPLICIT) AND (UTF8MB4_GENERAL_CI,IMPLICIT) 错误解决

写了一个查询所有上级的sql

  1.   SELECT
  2.   T0.*,T1.lower_count,T1.aicp,T1.user_level
  3.   FROM
  4.   (
  5.   SELECT
  6.   @r AS _id,
  7.   (
  8.   SELECT
  9.   @r := invite_user
  10.   FROM
  11.   fa_user
  12.   WHERE
  13.   id = _id
  14.   ) AS invite_user1,
  15.   @l := @l + 1 AS lvl
  16.   FROM
  17.   (SELECT @r := '用户id', @l := 0) vars,
  18.   fa_user h
  19.   WHERE
  20.   @r <> ''
  21.   ) T0
  22.   JOIN fa_user T1 ON T0._id = T1.id

报错SQLSTATE[HY000]: General error: 1267 Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '=',。MySQL 8.0.20

我看了下数据库的字符集排序规则 

ILLEGAL MIX OF COLLATIONS (UTF8MB4_0900_AI_CI,IMPLICIT) AND (UTF8MB4_GENERAL_CI,IMPLICIT) 错误解决

表的字符集排序规则 

ILLEGAL MIX OF COLLATIONS (UTF8MB4_0900_AI_CI,IMPLICIT) AND (UTF8MB4_GENERAL_CI,IMPLICIT) 错误解决

表字段的字符集排序规则 

ILLEGAL MIX OF COLLATIONS (UTF8MB4_0900_AI_CI,IMPLICIT) AND (UTF8MB4_GENERAL_CI,IMPLICIT) 错误解决

解决方法:在my.cnf中也做相同编码的配置

  1.   [client]
  2.   default-character-set = utf8mb4
  3.    
  4.   [mysqld]
  5.   character-set-client-handshake = FALSE
  6.   character_set_server = utf8mb4
  7.   collation-server = utf8mb4_0900_ai_ci
  8.    

如下图 

ILLEGAL MIX OF COLLATIONS (UTF8MB4_0900_AI_CI,IMPLICIT) AND (UTF8MB4_GENERAL_CI,IMPLICIT) 错误解决

进入mysql执行 show variables where Variable_name like 'collation%';查看

ILLEGAL MIX OF COLLATIONS (UTF8MB4_0900_AI_CI,IMPLICIT) AND (UTF8MB4_GENERAL_CI,IMPLICIT) 错误解决

上一篇:使用 GitLab CI/CD 和阿里云 CLI 自动部署前端项目


下一篇:java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_