若依系统安装配置后,点击“系统工具-代码生成-导入”时报错:

### Error querying database. 
Cause: java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=' 
### The error may exist in file [E:\test\RuoYi-Vue\ruoyi-generator\target\classes\mapper\generator\GenTableMapper.xml] 
### The error may involve com.ruoyi.generator.mapper.GenTableMapper.selectDbTableList-Inline 
### The error occurred while setting parameters 
### SQL: SELECT count(0) FROM information_schema.tables WHERE table_schema = (SELECT database()) AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' AND table_name NOT IN (SELECT table_name FROM gen_table) 
### Cause: java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=' ; 
uncategorized SQLException; SQL state [HY000]; error code [1267]; 
Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='; 
nested exception is java.sql.SQLException: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='

看上去是两个表的字段的编码不同的问题,检查了若依的所有表,发现都统一是utf8_unicode_ci,没有问题。

仔细看了报错信息,是下面的sql语问的出错。

SELECT count(0) FROM information_schema.tables WHERE table_schema = (SELECT database()) AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%' AND table_name NOT IN (SELECT table_name FROM gen_table)

是mysql自带的表information_schema.tables,与若依系统的表进行了关联查询。
而information_schema用的是utf8_general_ci编码排序,若依建数据库时,默认选了utf8_unicode_ci。

  • 于是,重建若依数据库,使用utf8_general_ci编码。

  • 问题解决。

############################################
注:utf8_general_ci和utf8_unicode_ci的区别
https://blog.csdn.net/testcs_dn/article/details/70157144
看了一下,对于中文和英文,两种排序规则差别不大,utf8_general_ci还更快一点。

Logo

快速构建 Web 应用程序

更多推荐