栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

MySQL排序规则混合冲突

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

MySQL排序规则混合冲突

"org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.springframework.jdbc.UncategorizedSQLException: ↵

### Error querying database. Cause: java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation 'find_in_set'↵

### The error may exist in URL [jar:file:/portal/programs/portal-service/portal-service-3.2.7-SNAPSHOT.jar!/BOOT-INF/lib/dao-simple-system-3.2.5-SNAPSHOT.jar!/mapper-simple-system/SysFunctionsMapper.xml]↵

### The error may involve com.sitech.cmap.dao.simple.system.mapper.SysFunctionsMapper.queryFunctionsByParentId-Inline↵

### The error occurred while setting parameters↵

### SQL: SELECt * FROM sys_functions,( SELECt queryChildrenFuncInfo (?) functionIds ) t WHERe FIND_IN_SET(id,functionIds)↵

### Cause: java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation 'find_in_set'↵;

 uncategorized SQLException for SQL []; SQL state [HY000]; error code [1267]; Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation 'find_in_set'; nested exception is java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation 'find_in_set'"

很不幸,再次遇到了排序规则的冲突。我检查了一遍表排序规则和字段排序规则,都是utf8_general_ci,并没有出现排序规则混合的情况。

有一个值得注意的关键字出现了:FIND_IN_SET。

现在怀疑是需要一个函数去执行存储过程:

DELIMITER $$
CREATE FUNCTION `queryChildrenFuncInfo`(areaId varchar(1000)) RETURNS varchar(4000) CHARSET utf8
BEGIN
DECLARE sTemp VARCHAr(4000);
DECLARE sTempChd VARCHAr(4000);

SET sTemp='$';
SET sTempChd = CAST(areaId AS CHAR);

WHILE sTempChd IS NOT NULL DO
SET sTemp= CONCAt(sTemp,',',sTempChd);
SELECT GROUP_CONCAt(id) INTO sTempChd FROM sys_functions WHERe FIND_IN_SET(parent_id,sTempChd)>0;
END WHILE;
RETURN sTemp;
END $$
DELIMITER ;

果然是这两个字段的排序规则问题。但是大家的规则都是一样的呀,为什么还报错呢?

这时候,我们打开了库的排序规则,发现用的居然是unicode的,和表的general不一样!

于是,把需要find_in_set的两个字段都改成了unicode,就可以正常运行了。

但是不久之后,我部署了另一个系统,排序规则又出现了问题,就一不做二不休,把库、表和字段的所有排序规则都改成了unicode,终于正常了。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/760526.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号