zoukankan      html  css  js  c++  java
  • 日常问题记录--插入记录时报 Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation '=' 错误

    背景:

    写一个数据DB操作时,日志报Illegal mix of collations (latin1_swedish_ci,COERCIBLE) and (gbk_chinese_ci,COERCIBLE) for operation '=' 错误;

    原因:

    1、插入式代码中的数据类型为GBK;

    2、DB建表时忘记修改默认的编码格式(默认为 Collation: latin1_swedish_ci 格式);

    1、2结合之后,插入数据编码错误;

    定位方法:

    1、查看DB表的字段编码 show full columns from tablename;

    2、检查struts编码

    修改方法:

    1、修改数据库DB的字段设置;

    mysql> SHOW VARIABLES LIKE 'character_set_%';
    +--------------------------+----------------------------+
    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | latin1 |
    | character_set_connection | latin1 |
    | character_set_database | latin1 |
    | character_set_results | latin1 |
    | character_set_server | latin1 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    7 rows in set (0.00 sec)
    mysql> SHOW VARIABLES LIKE 'collation_%';
    +----------------------+-------------------+
    | Variable_name | Value |
    +----------------------+-------------------+
    | collation_connection | latin1_swedish_ci |
    | collation_database | latin1_swedish_ci |
    | collation_server | latin1_swedish_ci |
    +----------------------+-------------------+
    3 rows in set (0.00 sec)
    依次执行:
    set character_set_client =gbk;
    set character_set_connection =gbk;
    set character_set_database =gbk;
    set character_set_results =gbk;
    set character_set_server =gbk;
    set character_set_system =gbk; --此处utf-8也可以
    然后执行:
    SET collation_server = gbk_chinese_ci
    SET collation_database = gbk_chinese_ci
    SET collation_connection =gbk_chinese_ci

    2、修改对应表的编码

     alter table tablename convert to character set gbk;

    不会炒菜的非专业测试人员
  • 相关阅读:
    java实现LFU算法
    2.1 测试函数-Rastrigin函数
    VM虚拟机如何与主机共享文件夹
    .bashrc文件和.bash_profile文件的区别
    1.2 准备工作
    1.1 JSOP架构
    vue中页面跳转拦截器的实现方法
    Javascript性能优化阅读笔记
    理解 e.clientX,e.clientY e.pageX e.pageY e.offsetX e.offsetY
    Vue.directive()的用法和实例
  • 原文地址:https://www.cnblogs.com/carterzhang/p/4374068.html
Copyright © 2011-2022 走看看