• mysql中一次字符集和排序规则引起的sql查询报错


    先看sql

      o.city_name             AS '城市',
      o.city_code             AS '城市编码',
      o.comp_name             AS '公司',
      o.comp_code             AS '分公司编码',
      b.brand_name            AS '品牌',
      a.account_code          AS '被处罚系统号',
      l.occur_time            AS '处罚发生日期',
      l.penalize_time         AS '处罚最终判罚日期',
      l.create_time           AS '处罚数据导入时间',
      l.violation_behavior    AS '违规行为名称',
      l.reason                AS '事件描述',
      l.ryb_category          AS '红黄线',
      l.add_score             AS '分值',
      l.credit_score_log_type AS '类别'
    FROM credit.credit_account a RIGHT JOIN credit.credit_score_log l ON l.credit_account_id = a.id
      LEFT JOIN credit.org o ON o.comp_code = l.comp_code
      LEFT JOIN credit.brand_comp b ON b.comp_code = o.comp_code.user_credit_score_log u ON u.user_code = a.account_code;
    

      

    报错提示:[HY000][1267] Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='

    怀疑是 字符集 或者 排序规则 对应不上,于是通过mysql指令排查下字符集

    SHOW FULL COLUMNS FROM credit.credit_account;
    SHOW FULL COLUMNS FROM credit.org;
    SHOW FULL COLUMNS FROM credit.credit_score_log;
    SHOW FULL COLUMNS FROM credit.brand_comp;
    

      

    credit_account表,org表,credit_score_log表,brand_comp表 四张表字符集分别如下:

    经过分析发现 最后一张表 brand_comp 的varchar字段Collation 是  utf8mb4_unicode_ci,前三张表varchar字段段Collation 都是 utf8mb4_general_ci

    于是更改表的字符集和排序规则,命令如下

    ALTER TABLE brand_comp CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
    

      此时再查询最后一张表

    排序规则更改后,再执行sql,完美运行,问题解决!

  • 相关阅读:
    ch4-SPSS Statistics操作进阶
    ch3-SPSS Statistics操作入门
    概率论与数理统计-ch7-参数估计
    概率论与数理统计-ch6-样本与抽样分布
    概率论与数理统计-ch5-大数定律及中心极限定理
    概率论与数理统计-ch4-随机变量的数字特征
    概率论与数理统计-ch3-多维随机变量及其分布
    Maven的依赖冲突
    eclipse下的server插件
    JQuery了解
  • 原文地址:https://www.cnblogs.com/wanghongsen/p/9727402.html
Copyright © 2020-2023  润新知