• MySQL语句错误:Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT)


    两张表的字段分别是两种不同的比较规则,在进行联表查询的时候就会出现上述错误。
    字符比较规则有各个层级的,比如数据库、表、字段,这里只需要保证字段的比较规则一致即可。但是为了整体一致,除了特殊的业务需求,我们最好还是保证库、表、字段的比较规则一致。

    -- ----------------------------
    -- Table structure for administrative_area
    -- ----------------------------
    DROP TABLE IF EXISTS `administrative_area`;
    CREATE TABLE `administrative_area` (
    `id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
    `create_time` datetime(6) DEFAULT NULL,
    `create_user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `last_update_time` datetime(6) DEFAULT NULL,
    `last_update_user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL,
    `code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
    `level` int(0) NOT NULL,
    `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
    `parent_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL
    ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;

    这里给出一张表结构,然后在这个表结构的基础上,把表和字段都调整为utf8mb4_bin,给出修正的例子:

    ------表修改------

    show table status from dubbo_play like '%administrative_area%';

    此时表的collations如下图所示:

    此时修改表的collate
    ALTER TABLE `administrative_area` CHARACTER SET = utf8mb4 COLLATE = utf8mb4_bin;
    此时的结果:

    ------字段修改------
    修改完表的比较规则之后,我们看看字段的状态:

    所以如果此时执行联表查询,还是会报错,我们需要把字段修改为相同的比较规则:

    ALTER TABLE `administrative_area` MODIFY `id` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;
    ALTER TABLE `administrative_area` MODIFY `create_time` datetime(6) DEFAULT NULL;
    ALTER TABLE `administrative_area` MODIFY `create_user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL;
    ALTER TABLE `administrative_area` MODIFY `last_update_time` datetime(6) DEFAULT NULL;
    ALTER TABLE `administrative_area` MODIFY `last_update_user_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL;
    ALTER TABLE `administrative_area` MODIFY `code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;
    ALTER TABLE `administrative_area` MODIFY `level` int(0) NOT NULL;
    ALTER TABLE `administrative_area` MODIFY `name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;
    ALTER TABLE `administrative_area` MODIFY `parent_code` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL;

    此时的字段状态:

  • 相关阅读:
    ubuntu17.10 源
    _nl_intern_locale_data: Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed
    shell | crontab 定时任务
    python将负数转为16进制无符号数
    vooya --- a YUV player and a generic raw data player
    clion 查看代码 多次查看后如何一步一步回退到最初查看的代码位置
    Unity3d XmlException: Text node cannot appear in this state的方案
    Unity2017灯光烘焙知识点
    unity加载ab后,场景shader不起效问题(物件表现黑色)
    BMFont制作美术字体
  • 原文地址:https://www.cnblogs.com/bruceChan0018/p/15795506.html
Copyright © 2020-2023  润新知