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;