생계유지형 개발자/Stack Over Flow 한국판

[Mysql] Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '='

이 가을 2020. 8. 7. 12:34

# 오류

단순한 JOIN이 포함된 조회쿼리를 실행했는데 아래와 같은 오류가 난다.

[ERROR] Illegal mix of collations (utf8mb4_unicode_ci,IMPLICIT) and (utf8mb4_general_ci,IMPLICIT) for operation '=' 0.0043 sec
select * from site_msg s join footer f on (s.`uuid` = f.`html`) where s.target_field = 'html' LIMIT 0, 1000	Error Code: 1267. 

# 원인

JOIN 조건에 있는 각 테이블의 컬럼의 문자셋이 상이해서 발생하는 오류라고 한다.

# 해결

데이터베이스와 테이블의 문자셋을 변경했다.

-- 데이터베이스 문자셋 변경
alter database [DB_NAME] character set utf8 collate utf8_general_ci;

-- 테이블 문자셋 변경
alter table [TABLE1] convert to character set utf8 collate utf8_general_ci;
alter table [TABLE2] convert to character set utf8 collate utf8_general_ci;

 

※ 참고

https://blog.boxcorea.com/wp/archives/2685