
java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_
### Cause: java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='] with root causejava.sql.SQLException: Illegal mix of coll
·
报错背景
今天在MyBatis进行联表查询时报错:
### Cause: java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='] with root cause
java.sql.SQLException: Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation '='
at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129)
at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:370)
检查了下SQL语句写的并没有问题。
报错原因
看到报错提示“utf8mb4_general”和“utf8mb4_0900_ai_ci”便很自然联想到字符集编码,于是猜测可能是联表时相同字段的字符集编码不同导致报错,于是检查了一下两张表中的连接字段,果然不同。
表一的file_id字段排序规则:
表二的file_id字段排序规则:
解决方案
将二者排序规则修改为相同即可,问题解决。
更多推荐
所有评论(0)