2019-02-27 07:32:17.108 ERROR 21745 --- [nio-8086-exec-2] c.h.h.rest.configurer.WebMvcConfigurer : 接口[/flyfish/h5/user/register]出
现异常 :[{}]java
org.springframework.jdbc.UncategorizedSQLException: ### Error querying database. Cause: java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '=' ### The error may exist in com/hn/haoniu/businesscore/dao/UserMapper.java (best guess) ### The error may involve com.hn.haoniu.businesscore.dao.UserMapper.selectOne-Inline ### The error occurred while setting parameters ### SQL: SELECT id,invite_code,recommend_user_id,nick_name,phone,password,real_name,sex,area,user_type,robot_type,head_img,salt,lei_type,token_id,create_time,update_time,del_flag FROM user WHERE nick_name = ? ### Cause: java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '=' ; uncategorized SQLException for SQL []; SQL state [HY000]; error code [1267]; Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '='; nested exception is java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8mb4_general_ci,COERCIBLE) for operation '=' at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) ~[spring-jdbc-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.3.9.RELEASE.jar:4.3.9.RELEASE] at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73) ~[mybatis-spring-1.3.1.jar:1.3.1] at org.mybatis.spring.SqlSessionTemplate$SqlSessionInte
解决方法spring
java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=',意思是说字符编码不同,不能进行比较,也就是说数据库内部的编码都不同,有的数据是latin1_swedish_ci,有的数据是utf8_general_ci,,所以解决此问题的核心就是将数据库全部的编码进行统一。sql
一、查看数据库编码,使用sql语句:show variables like 'character_set_%';数据库
正确的以下图:mybatis
若是编码不对,可以使用如下sql语句进行修改:app
set character_set_client=utf8; set character_set_connection=utf8; set character_set_database=utf8; set character_set_results=utf8; set character_set_server=utf8; set character_set_system=utf8;
二、查看排序规则,使用sql语句:show variables like 'collation_%';编码
正确的以下图:rest
若是不对,可以使用如下sql语句进行修改:code
set collation_connection=utf8; set collation_database=utf8; set collation_server=utf8;