Illegal mix of collations (XXX) and (XXX) for operation ‘XXX’
问题描述:
mybatis使用INSTR的时候报错(数据库为MySQL)—— Illegal mix of collations (XXX) and (XXX) for operation 'XXX’
– Cause: java.sql.SQLException: Illegal mix of collations (utf8_bin,NONE) and (utf8mb4_general_ci,COERCIBLE) for operation ‘instr’
– uncategorized SQLException; SQL state [HY000]; error code [1267]; Illegal mix of collations (utf8_bin,NONE) and (utf8mb4_general_ci,COERCIBLE) for operation ‘instr’; nested exception is java.sql.SQLException: Illegal mix of collations (utf8_bin,NONE) and (utf8mb4_general_ci,COERCIBLE) for operation ‘instr’
原因分析:
排序规则不同导致的
解决方案:
1、查询SQL语句中使用到的数据表和字段的排序规则
-- 查询数据表的排序规则
select table_name, table_collation
from information_schema.tables
where table_schema = database()
and table_name in ('表名1', '表名2');
-- 查询字段的排序规则
select table_name, column_name, collation_name
from information_schema.columns
where table_schema = database()
and collation_name is not null
and table_name in ('表名1', '表名2');
2、然后修改不一样的数据表的排序规则(如果能定位是哪两个表起冲突了的话就直接改对应表就好,不知道的话就只能全改了)
-- 修改排序规则
-- 这里和编码规则一起修改了,编码规则和排序规则好像还有对应关系
-- 排序规则(collate)必须以编码规则(set)开头
-- 修改数据表,表中的字段也会一起被修改
ALTER TABLE 表名 CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
-- 修改某个字段
ALTER TABLE 表名 MODIFY 字段名 VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
注意:
那个查询表的排序规则的时候,排序规则要和其他大多数数据表的排序规则保持一致,要不然其他功能会出问题。
-- 查询数据库中全部数据表的排序规则
select table_name, table_collation
from information_schema.tables
where table_schema = database();
Illegal mix of collations (XXX) and (XXX) for operation ‘XXX’相关推荐
- 编码不一致问题-Illegal mix of collations
在解决bug时候碰到一个Illegal mix of collations问题,这个因为编码不一致到导致的错误.错误发生率较为高.经常发生在时间的比较上面.较为常见的一劳永逸的办法,是更改数据库的编码 ...
- Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '=
问题描述:MySQL进行字符串比较时发生错误: SELECT a.equ_no, b.fullCode FROM equipment a, ( SELECT t.*, getEquTypeFullCo ...
- 【Java】application run failed Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and
springboot 启动时报这个错:application run failed Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and ...
- 调用存储过程时报错:Illegal mix of collations
调用存储过程时,发生报错,信息如下: ERROR 1267 (HY000): Illegal mix of collations (gb2312_chinese_ci,IMPLICIT) and (l ...
- MySQL replication illegal mix of collations
MySQL replication case 一则 转载:http://www.vmcd.org/2013/09/mysql-replication-case-%E4%B8%80%E5%88%99/ ...
- 报错:Illegal mix of collations
问题: 服务端报错:Error: ER_CANT_AGGREGATE_2COLLATIONS: Illegal mix of collations (latin1_swedish_ci,IMPLICI ...
- Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_unicode_ci,IMPLICIT) for operat
1.问题 今天又在mysql中遇到了,吐血. 2.解决方案 SQL最后加上 COLLATE utf8mb4_unicode_ci SELECT t2.cust_id as cust_id_ex,t1. ...
- Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operat
多表关联查询报错先看报错结果 我想通过这个org_post_user_name 表和这个has 的复合表进行查询 通过这个条件关联在一起查询 where ssorg.org = has.qwe 然后 ...
- MySQL:Illegal mix of collations (utf8_general_ci,COERCIBLE) and (gbk_chinese_ci,IMPLICIT) for operat
MySQL:Illegal mix of collations (utf8_general_ci,COERCIBLE) and (gbk_chinese_ci,IMPLICIT) for operat ...
最新文章
- kafka streams_如何使用Kafka Streams实施更改数据捕获
- php将配置信息写入文件,Php写入配置文件的经典漏洞
- 基于触发机制的脚本系统
- 我常用的Markdown公式符号
- ffmpeg命令 抓屏_使用FFmpeg从视频中截图的命令 | 学步园
- iphone数据迁移到新iphone_Mac专业iPhone数据恢复软件----Omni Recover
- XXE漏洞攻击与防御
- linux下的一些常见命令学习,学习猿地-Linux下的常见命令总结
- 热电偶校验仪使用说明_APSL311系列压力校验仪
- WCF元数据交互及其序列化
- 【java学习之路】(java SE篇)006.异常
- 方法:如何解决NetShareEnum返回ERROR_NO_UNICODE_TRANSLATION(1113)的问题
- 安装黑苹果先判断你的电脑硬件是否有驱动支持
- 使用VSCode运行C语言
- 移动App测试中的最佳做法
- Uber面向中印开发者公布SDK,支持第三方应用集成服务
- java技术路线思维导图_开题报告中的研究方法及技术路线指的啥?
- 如何卸载中孚保密终端_广州从化东莞万江保密档案销毁价格_绿航环保
- 搭建私服环境及私服的使用-将第三方jar上传私服
- 汽车诊断-KWP2000协议