프로그래밍/SQL
[MySQL] 에러 "ERROR 1267 (HY000): Illegal mix of collations~"
김뎀뎀
2023. 2. 22. 19:11
⚠️ 에러 발생 상황
SELECT c.police_station, p.name
FROM crime_status c, police_station p
WHERE p.name LIKE CONCAT('서울',c.police_station,'경찰서')
GROUP BY c.police_station, p.name'
```
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation 'like'
```
police_station 테이블의 name 컬럼을 crime_station 테이블의 poilce_station 컬럼과 문자열을 조합해 LIKF로 비교하려 했는데 에러가 발생했다
ERROR 1267 (HY000): Illegal mix of collations (utf8mb4_general_ci,IMPLICIT) and (utf8mb4_0900_ai_ci,IMPLICIT) for operation 'like'
두 테이블의 collation(mysql에서 문자열이 정렬할지 결정하는 규칙이라고 함)이 일치하지 않아서 발생하는 오류라고 하는데, 에러 안에 보면 하나는 'utf8mb4_general_ci' 로, 하나는 'utf8mb4_0900_ai_ci'로 되어있음을 파악할 수 있다.
💡 에러 해결 방법
alter table police_station convert to character set utf8mb4 collate utf8mb4_general_ci;
alter table crime_status convert to character set utf8mb4 collate utf8mb4_general_ci;
두 테이블의 collation을 맞춰주면 된다.