mysql跨库字符集不同查询报错解决:1267Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general.
问题描述:select d.* from `ckcx_sysinfo`.department d , department_course sc where d.ruid=sc.department_ruid在进行双表联合查询时,由于两边数据库的编码不一致,ckcx_sysinfo使用的是 utf8mb4_0900_ai_ci,当前库使用的是utf8mb4_general_ci,所以导致报错1267
·
问题描述:
select d.* from `ckcx_sysinfo`.department d , department_course sc where d.ruid=sc.department_ruid
在进行双表联合查询时,由于两边数据库的编码不一致,ckcx_sysinfo使用的是 utf8mb4_0900_ai_ci,
当前库使用的是utf8mb4_general_ci,所以导致报错
1267 - Illegal mix of collations (utf8mb4_0900_ai_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation ‘=’
问题解决:
使用CONVERT(d.ruid USING gbk )指定编码
select d.* from `ckcx_sysinfo`.department d , department_course sc where CONVERT(d.ruid USING gbk )=sc.department_ruid
扩展
MySql 内置方法 CONVERT (‘column’ USING ‘gbk’) 转换编码
同时可以对于中文字符进行排序
mysql 排序方法 “order by” 排序规则:
数据库编码: 排序
utf-8mb4 按英文字母规则排序 "a,b,c… "
gbk 按汉字首字母排序
更多推荐
已为社区贡献1条内容
所有评论(0)