Mysql Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operat

2020-09-11 10:57:09 浏览数 (1)

MySQL字符串比较bug:

代码语言:javascript复制
select * from table_a a left join table_b b on a.field_a = b.field_b

error:

代码语言:javascript复制
Illegal mix of collations (utf8_unicode_ci,IMPLICIT) and (utf8_general_ci,IMPLICIT) for operation '='

cause:两表编码方式不一致。

resolve:将比较等式的一边进行字符串转换,如:“CONVERT(a.field_a USING utf8) COLLATE utf8_unicode_ci

代码语言:javascript复制
select * from table_a a left join table_b b on CONVERT(a.field_a USING utf8) COLLATE utf8_unicode_ci = b.field_b

注:utf8_general_ci:校对速度快,准确度差。

utf8_unicode_ci:准确度高,校对速度慢。

0 人点赞