Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMP
• mysql教程• 發佈:2018-10-08
mysql中執行字串比較操作時出現了下面的錯誤資訊:
Error Code: 1267. Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '='
執行的sql語句如下:
select gu.id as github_id, gu.avatar, gu.site_feed_url,gu.home_url,f.id as feedId,f.flags as feedFlags
from github_user gu
inner join f_feed f on
replace((replace((SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(gu.site_url, '//', ''), '/', 1), '*', -2)), 'http:','')),'https:','')
= f.host
where f.flags &; 2 = 0
上面的inner join條件的=比較出錯了,可以通過在比較表示式後新增COLLATE utf8_unicode_ci來設定字符集,從而達到比較的目的, 下面是可以正常執行的sql
select gu.id as github_id, gu.avatar, gu.site_feed_url,gu.home_url,f.id as feedId,f.flags as feedFlags
from github_user gu
inner join f_feed f on
replace((replace((SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(gu.site_url, '//', ''), '/', 1), '*', -2)), 'http:','')),'https:','')
= f.host COLLATE utf8_unicode_ci
where f.flags &; 2 = 0
