2019-02-27 07:32:17.108 ERROR 21745 --- [nio-8086-exec-2] c.h.h.rest.configurer.WebMvcConfigurer : 接口[/flyfish/h5/user/register]出
  
  现异常 :[{}]
  
  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
  
  解决方法
  
  java.sql.SQLException: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=',意思是说字符编码不一样,不能进行比较,也就是说数据库内部的编码都不一样,有的数据是latin1_swedish_ci,有的数据是utf8_general_ci,,因此解决此问题的核心就是将数据库所有的编码进行统一。
  
  1、查看数据库编码,使用sql语句:show variables like 'character_set_%';
  
  正确的如下图:
  
  如果编码不对,可使用以下sql语句进行修改:
  
  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;
  
  2、查看排序规则,使用sql语句:show variables like 'collation_%';
  
  正确的如下图:
  
  如果不对,可使用以下sql语句进行修改:
  
  set collation_connection=utf8;
  
  set collation_database=utf8;
  
  set collation_server=utf8;
  
  SpringBoot 的自动配置如此强大,比如我们经常使用的@Enable* 注解来开启对某方面的支持。那么@Enable* 注解的原理是什么呢?
  
  一、@Enable* 注解与 @Import 注解之间的关系
  
  @Enable* 举例:
  
  @EnableScheduling 开启计划任务的支持
  
  @EnableAsync 开启异步方法的支持
  
  @EnableAspectJAutoProxy 开启对 AspectJ 代理的支持
  
  @EnableTransactionManagement 开启对事务的支持
  
  @EnableCaching 开启对注解式缓存的支持
  
  等等
  
  我们观察这些@Enable* 的源码可以看出,所有@Enable* 注解都是有@Import的组合注解,@Enable* 自动开启的实现其实就是导入了一些自动配置的Bean
  
  看下 Spring Boot Reference Guide原文
  
  You need not put all your @Configuration into a single class. The @Import annotation
  
  can be used to import additional configuration classes.
  
  您不需要把所有的 @Configuration 放到一个类中。@Import 注解可以导入额外的配置类。
  
  @Import 注解的最主要功能就是导入额外的配置信息
  
  二、 @Import 注解的用法
  
  官方介绍:
  
  * <p>Provides functionality equivalent to the {@code <import/>} element in Spring XML.
  
  * Allows for importing {@code @Configuration} classes, {@link ImportSelector} and
  
  * {@link ImportBeanDefinitionRegistrar} implementations, as well as regular component
  
  * classes (as of 4.2; analogous to {@link AnnotationConfigApplicationContext#register}).
  
  有以下三种使用方式
  
  1、直接导入配置类(@Configuration 类)
  
  @Target(ElementType.TYPE)
  
  @Retention(RetentionPolicy.RUNTIME)
  
  @Import(SchedulingConfiguration.class)
  
  @Documented
  
  public @interface EnableScheduling {
  
  }
  
  可以看到EnableScheduling注解直接导入配置类SchedulingConfiguration,这个类注解了@Configuration,且注册了一个scheduledAnnotationProcessor的Bean,SchedulingConfiguration的源码如下:
  
  @Configuration
  
  @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
  
  public class SchedulingConfiguration {
  
  @Bean(name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)
  
  @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
  
  public ScheduledAnnotationBeanPostProcessor scheduledAnnotationProcessor() {
  
  return new ScheduledAnnotationBeanPostProcessor();
  
  }
  
  }
  
  2、依据条件选择配置类(实现 ImportSelector 接口)
  
  如果并不确定引入哪个配置类,需要根据@Import注解所标识的类或者另一个注解(通常是注解)里的定义信息选择配置类的话,用这种方式。
  
  ImportSelector接口只有一个方法
  
  String[] selectImports(AnnotationMetadata importingClassMetadata);
  
  AnnotationMetadata:用来获得当前配置类上的注解
  
  例:
  
  @Target(ElementType.TYPE)
  
  @Retention(RetentionPolicy.RUNTIME)
  
  @Documented
  
  @Import(AsyncConfigurationSelector.class)
  
  public @interface EnableAsync {
  
  Class<? extends Annotation> annotation() default Annotation.class;
  
  boolean proxyTargetClass(www.jiahuayulpt.com) default false;
  
  AdviceMode mode() default AdviceMode.PROXY;
  
  int order() default Ordered.LOWEST_PRECEDENCE;
  
  }
  
  AsyncConfigurationSelector继承AdviceModeImportSelector,AdviceModeImportSelector类实现ImportSelector接口 根据AdviceMode的不同来选择生明不同的Bean
  
  public class AsyncConfigurationSelector extends AdviceModeImportSelector<EnableAsync> {
  
  private static final String ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME =
  
  "org.springframework.scheduling.aspectj.AspectJAsyncConfiguration";
  
  @Override
  
  @Nullable
  
  public String[] selectImports(AdviceMode adviceMode) {
  
  switch (adviceMode) {
  
  case PROXY:
  
  return new String[] {ProxyAsyncConfiguration.class.getName()};
  
  case ASPECTJ:
  
  return new String[] {ASYNC_EXECUTION_ASPECT_CONFIGURATION_CLASS_NAME};
  
  default:
  
  return null;
  
  }
  
  }
  
  }
  
  3、动态注册Bean(实现 ImportBeanDefinitionRegistrar 接口)
  
  一般只要用户确切知道哪些Bean需要放入容器的话,自己可以通过spring 提供的注解来标识就可以了,比如@Component,@Service,@Repository,@Bean等。 如果是不确定的类,或者不是spring专用的,所以并不想用spring的注解进行侵入式标识,那么就可以通过@Import注解,实现ImportBeanDefinitionRegistrar接口来动态注册Bean。 比如:
  
  @Target(ElementType.TYPE)
  
  @Retention(RetentionPolicy.RUNTIME)
  
  @Documented
  
  @Import(AspectJAutoProxyRegistrar.class)
  
  public @interface EnableAspectJAutoProxy {
  
  boolean proxyTargetClass(www.myzx157.com) default false;
  
  boolean exposeProxy() default false;
  
  }
  
  AspectJAutoProxyRegistrar实现了ImportBeanDefinitionRegistrar接口,ImportBeanDefinitionRegistrar的作用是在运行时自动添加Bean到已有的配置类,通过重写方法:
  
  public void registerBeanDefinitions(
  
  AnnotationMetadata importingClassMetadata,www.yongshiyule178.com BeanDefinitionRegistry registry);
  
  AnnotationMetadata 参数用来获得当前配置类上的注解
  
  BeanDefinitionRegistry 参数用来注册Bean
  
  源码:
  
  @Override
  
  public void registerBeanDefinitions(
  
  AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
  
  AopConfigUtils.registerAspectJAnnotationAutoProxyCreatorIfNecessary(registry);
  
  AnnotationAttributes www.yaxingyule.cn enableAspectJAutoProxy www.leyouzaixian2.com =
  
  AnnotationConfigUtils.www.yingxionghui1.cn attributesFor(importingClassMetadata, EnableAspectJAutoProxy.class);
  
  if (enableAspectJAutoProxy != www.taoyang2vip.com null) {
  
  if (enableAspectJAutoProxy.www.yongshi123.cn getBoolean("proxyTargetClass")) {
  
  AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
  
  }
  
  if (enableAspectJAutoProxy.getBoolean( www.feishenbo.cn/ "exposeProxy")) {
  
  AopConfigUtils.forceAutoProxyCreatorToExposeProxy(registry);

字符编码问题mysql的更多相关文章

  1. linux mysql字符编码问题

    发布:thatboy   来源:脚本学堂     [大 中 小] 本文介绍下,linux环境中mysql字符编码问题的解决办法,有遇到mysql编码问题的朋友,可以参考下本文的介绍,希望对你有一定的帮 ...

  2. 拨开字符编码的迷雾--MySQL数据库字符编码

    拨开字符编码迷雾系列文章链接: 拨开字符编码的迷雾--字符编码概述 拨开字符编码的迷雾--编译器如何处理文件编码 拨开字符编码的迷雾--字符编码转换 拨开字符编码的迷雾--MySQL数据库字符编码 1 ...

  3. MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) - 转载

    MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) MySQL的默认编码是Latin1,不支持中文,那么如何修改MySQL的默认编码呢,下面以设置UTF-8为例来说明. 需 ...

  4. MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码)

    MySQL基础配置之mysql的默认字符编码的设置(my.ini设置字符编码) MySQL的默认编码是Latin1,不支持中文,那么如何修改MySQL的默认编码呢,下面以设置UTF-8为例来说明. 需 ...

  5. 字符编码,存储引擎,MySQL字段类型,MySQL字段约束条件

    字符编码 查看MySQL默认编码命令:\s """ 如果是5.X系列 显示的编码有多种 latin1 gbk 如果是8.X系列 显示的统一是utf8mb4 utf8mb4 ...

  6. django管理数据库之中文字符编码问题

    django中通过models创建数据库字符编码文字mysql数据库中默认的字符编码都为latin1,插入中文时会出现以下的错误类型 1366 - Incorrect string value: '\ ...

  7. mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat'

    mysql5.6修改字符编码,ERR:Illegal mix of collations for operation 'concat' 1.问题起因:搭建环境初始化mysql的时候看到mysql配置文 ...

  8. mysql 5.5 修改字符编码

    修改/etc/mysql/my.cnf 配置文件: 最后重启mysql 服务,再查看: 编码已经改好了,可以支持中文字符编码了.

  9. mysql命令行修改字符编码

    1.修改数据库字符编码 mysql> alter database mydb character set utf8 ; 2.创建数据库时,指定数据库的字符编码 mysql> create ...

随机推荐

  1. mysql删除关联表数据

    DELETE og,oiFROM order_goods og, order_info oiWHERE oi.order_id = og.order_id and oi.user_id = 6

  2. 软件设计、DDD概念及落地时的一些零碎思考和记录

    DDD理解 DDD体现的是对现实的充分尊重. 1.尊重业务现实,领域专家.领域语言等概念 2.尊重团队现实 3.尊重变化 Application 对某一业务线的整体掌控,流程组装,进度管理,存储时机掌 ...

  3. 20155318 《网络攻防》 Exp7 网络欺诈防范

    20155318 <网络攻防> Exp7 网络欺诈防范 基础问题 通常在什么场景下容易受到DNS spoof攻击 DNS spoof攻击即执行DNS欺骗攻击,通过使用Ettercap来进行 ...

  4. mfc 线程的诞生和死亡

    知识点:  线程概念  线程的诞生  线程的死亡 一. 线程: 线程,是程序执行流的最小单元. 另外,线程是进程中的一个实体,是被系统独立调度和分派的基本单位,线程自己不拥有系统资源,只拥有一点 ...

  5. Python学习之路(一)之Python基础1

    目录 Python基础初识 1.Python介绍 1.1.Python简介 1.2.Python特点 1.3.Python应用领域 1.4.Python解释器的种类 2.Python基础初识 2.1. ...

  6. Redux系列02:一个炒鸡简单的react+redux例子

    前言 在<Redux系列01:从一个简单例子了解action.store.reducer>里面,我们已经对redux的核心概念做了必要的讲解.接下来,同样是通过一个简单的例子,来讲解如何将 ...

  7. SpringBoot入门学习记录(一)

    最近,SpringBoot.SpringCloud.Dubbo等框架非常流行,作为Coder里的一名小学生,借着改革开放的东风,自然也是需要学习学习的,于是将学习经历记录于此,以备日后查看. 官网:h ...

  8. aiohttp基本及进阶使用

    客户端使用 发起请求 让我们从导入aiohttp模块开始: import aiohttp 好啦,我们来尝试获取一个web页面.比如我们来获取下GitHub的时间轴. async with aiohtt ...

  9. Python对Selenium调用浏览器进行封装包括启用无头浏览器,及对应的浏览器配置文件

    """ 获取浏览器 打开本地浏览器 打开远程浏览器 关闭浏览器 打开网址 最大化 最小化 标题 url 刷新 Python对Selenium封装浏览器调用 ------b ...

  10. Harbor 学习分享系列1 - centos7.4安装harbor1.5.2

    centos7.4安装harbor1.5.2 前言 本系列分享将Harbor有关教程:分享形式会以百度云盘的形式进行分享,主要教程将以markdown格式进行分享:建议使用markdownpad2这款 ...