Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT)详解数据库

错误信息

select a.*  from hospital_info a ,  test b  where b.test_2 =a.city_code LIMIT 0, 1000
Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) 
for operation ‘=’ 0.000 sec


分析

根据异常信息,我们得知,b.test2校对规则是utf8_general_ci,a.city_code校对规则是utf8_unicode_ci,由于是不同的校对规则无法兼容,所以出现异常。

以下验证了,我们的上述猜想。

Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT)详解数据库Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT)详解数据库

解决办法

将test表改为utf8_general_ci即可

语法:alter table table_name convert to character set character_set_name [collate collation_name];

将表及表的所有列改为指定字符集和校对规则,避免了一列一列的修改。

比如,alter table test convert to character set  utf8  collate utf8_unicode_ci;修改后可以正常查询了。


原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/3746.html

(0)
上一篇 2021年7月16日
下一篇 2021年7月16日

相关推荐

发表回复

登录后才能评论