'MySQL'에 해당되는 글 1건

  1. 2007/01/19 MySQL에서 UTF 8 설정 - utf8_unicode_ci 완전정복 -

MySQL에서 UTF 8 설정 - utf8_unicode_ci 완전정복 -

View Comments



MySQL에서 UTF 8 설정

utf8_unicode_ci 완전정복


[과제]

MySQL을 다음 그림과 같이 설정해야 한다.

사용자 삽입 이미지



[해결]

MySQL 설치시 Character Set / Collation을 utf8로 설정한다.

사용자 삽입 이미지





















MySQL 설정파일 my.ini은 다음과 같이 구성된다.

** 코드 1 **
 
[mysql]

default-character-set=utf8

[mysqld]

# The default character set that will be used when a new schema or table is
# created and no character set is defined
default-character-set=utf8


필자의 호스팅 서버는 utf8 / utf8_unicode_ci로 설정되어 있는 걸로 알고 있다(얼마 전에 자세히 살펴 보니 그게 아니더라. 하지만, 어쩌랴… 시작하면 끝장을 보는 성격인걸 ㅡㅡ;).

데이터베이스 사랑넷에서
utf8_unicode_ci을 검색해보면, 대부분 이렇게 설정하라고 한다.

** 코드 2 **

init_connect=SET collation_connection=utf8_unicode_ci
init_connect=SET NAMES utf8
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_unicode_ci


하지만, 이렇게 할 경우에는 아래 그림처럼 character_set_client, character_set_connection, character_set_results, collation_connection은 latin1과 latin1_swedish_ci로 남아 있게 된다.

사용자 삽입 이미지


그래서 코드 2의 init_connect에 착안해서, my.ini에 다음과 같은 설정을 추가해보았다.

** 코드 3 **

init_connect=SET collation_connection=utf8_unicode_ci;
init_connect=SET character_set_client=utf8;
init_connect=SET character_set_results=utf8;
init_connect=SET character_set_connection=utf8;


이만하면 해결했으리라 기대하면서 MySQL를 멈추고 재시작해보았으나 아무런 변화가 없었다. 이와 비슷하게 여러 차례 시도했으나 허탕으로 끝났다. 그래서, HeidiSQL에서 쿼리를 실행해보았다.

여러 차례 시도했으나 허탕으로 끝났다. 그래서, HeidiSQL에서 쿼리를 실행해보았다.

** 코드 4 **

SET collation_connection=utf8_unicode_ci;
SET character_set_client=utf8;
SET character_set_results=utf8;
SET character_set_connection=utf8;


결과는 다음 그림과 같다.

사용자 삽입 이미지


다른 건 다 만족스럽지만, 유독 collation_connection만은 utf8_gerneral_ci로 설정되었다. 여기서, 의문점이 생긴다. 분명 utf8_unicode_ci로 지정하였건만, 왜 utf8_gerneral_ci로 설정된단 말인가?

혹시나 해서 SET collation_connection=utf8_roman_ci;로 쿼리를 실행해 봤다. 예상은 안 해봤지만, 여전히 utf8_gerneral_ci이었다. 그래서 collation_connection은 utf8_gerneral_ci로만 설정되는듯하고 잠정결론을 내릴뻔했다. MySQL 5.0 Reference Manual을 좀더 살펴본 결과 이 문제에 대한 직접적으로 언급되어 있진 않지만, SET collation_connection = @@collation_database; 라고 쓰인 부분이 눈에 들어왔다. 논리적으로는 collation_database가 utf8_unicode_ci로 설정되어 있으니, 결과적으로 성공하리라고 생각하고 실행해 보았다.

** 코드 5 **

SET collation_connection = @@collation_database;


결과는?


대성공!!

사용자 삽입 이미지


my.ini에서 init_connect로 설정하는 방법과 SET collation_connection=utf8_unicode_ci;에 대해 궁금한 점들이 남긴 하지만, 어쨌든 이로써 uf8 해결!!!

2007/01/19 14:43 2007/01/19 14:43

댓글0 Comments (+add yours?)

트랙백0 Tracbacks (+view to the desc.)

Newer Entries Older Entries