1267: Illegal mix of collations(非法的排序规则混用)
MySQL含义
在比较或组合操作(JOIN、WHERE、UNION、CONCAT)中,组合了两个排序规则不同的字符串,MySQL 无法确定应采用哪种排序规则。
原因
通常是比较字符集/排序规则不同的列(例如 utf8mb4_general_ci 与 utf8mb4_unicode_ci,或 latin1 与 utf8mb4),或列与连接排序规则不匹配。在用不同默认值创建表/数据库时很常见。
解决方法
使比较两边采用相同的排序规则:用 COLLATE 指定显式排序规则(例如 col1 = col2 COLLATE utf8mb4_unicode_ci)或使用 CONVERT(... USING ...)。作为永久方案,将受影响的列/表转换为统一的字符集和排序规则。同时统一连接排序规则(collation_connection)。
同一数据库的其他条目
- 3948Loading local data is disabled; this must be enabled on both the client and server sides(加载本地数据已禁用;必须在客户端和服务器端同时启用)
- 1075Incorrect table definition; there can be only one auto column and it must be defined as a key(表定义不正确;只能有一个自增列,且必须将其定义为键)
- 1055Expression not in GROUP BY (only_full_group_by)(表达式不在 GROUP BY 中)
- 1030Got error N from storage engine(从存储引擎收到错误 N)
- 1197Multi-statement transaction required more than 'max_binlog_cache_size'(多语句事务所需空间超过了 'max_binlog_cache_size')
- 1785Statement violates GTID consistency(语句违反 GTID 一致性)
- 3024Query execution was interrupted, maximum statement execution time exceeded(查询执行被中断,超出最大语句执行时间)