빅데이터 및 DB/MySQL

[MariaDB] UTF-8 캐릭터(Character) 설정 변경 방법

Steve Jang 2018. 8. 8. 09:57

아무래도 MariaDB와 MySQL의 만든 사람이 동일하다 보니 해당 포스팅은 MySQL에서도 동일하게 문제 해결이 될 것이나, 폴더 및 설치 세팅이 미세하게 다를 수 있다.


MariaDB를 설치하였는데 뭔가 빠진 느낌이 들어서 뭔가 곰곰히 생각해보니, Install 과정에서 캐릭터셋을 선택하는 것이 없었다는 것을 판단하였고, Toad for Mysql로 테이블을 생성 할 때, comment가 깨져있는 것을 발견했다 (이건, 빼도박도 못하는 캐릭터셋 문제)


보다시피, 테이블 Comment 설정 창에 캐릭터셋이 깨져 있는 것을 발견


MariaDB, MySQL은 캐릭터셋을 확실히 잡고 시작을 해야 나중에 참변을 방지할 수 있다.


확인 방법


C:\Windows\System32>mysql -u root -p

Enter password: **********

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 59

Server version: 10.2.13-MariaDB mariadb.org binary distribution


Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> show variables like 'c%';

+--------------------------+-----------------------------------------------+

| Variable_name            | Value                                         |

+--------------------------+-----------------------------------------------+

| character_set_client     | euckr                                         |

| character_set_connection | euckr                                         |

| character_set_database   | latin1                                        |

| character_set_filesystem | binary                                        |

| character_set_results    | euckr                                         |

| character_set_server     | latin1                                        |

| character_set_system     | utf8                                          |

| character_sets_dir       | C:\Program Files\MariaDB 10.2\share\charsets\ |

| check_constraint_checks  | ON                                            |

| collation_connection     | euckr_korean_ci                               |

| collation_database       | latin1_swedish_ci                             |

| collation_server         | latin1_swedish_ci                             |

| completion_type          | NO_CHAIN                                      |

| concurrent_insert        | AUTO                                          |

| connect_timeout          | 10                                            |

+--------------------------+-----------------------------------------------+

15 rows in set (0.00 sec)


질의를 c로 시작하는 변수를 출력하면, 현재 캐릭터셋이 어떻게 설정되어 있는지 확인이 가능하다. 현재 내 컴퓨터에는 euckr과 latin1 방식으로 되어 있는 것을 확인할 수 있고, 이것을 모두 utf8로 변경해보도록 하겠다.



설정 변경



C:/Program Files/MariaDB (버전)/data 폴더에 접근하면, my.ini 라는 파일이 있다. 이 파일을 우선 열어본다.


[mysqld]

datadir=C:/Program Files/MariaDB 10.2/data

port=3306

innodb_buffer_pool_size=2033M

[client]

port=3306

plugin-dir=C:/Program Files/MariaDB 10.2/lib/plugin


현재, 내 마리아DB에 있는 my.ini 파일은 위 내용처럼, 캐릭터셋을 설정하는 부분이 전혀 없다. euckr로 나오는걸 보면, 설정을 하지 않을 경우 내 환경의 캐릭터셋을 가지고 오는 것 같다. 내용에 캐릭터 셋을 추가 한후, 서버를 재시작한다.



[mysqld]

datadir=C:/Program Files/MariaDB 10.2/data

port=3306

innodb_buffer_pool_size=2033M

init_connect="SET collation_connection = utf8_general_ci"

init_connect="SET NAMES utf8"

character-set-server = utf8

collation-server = utf8_general_ci


[client]

port=3306

plugin-dir=C:/Program Files/MariaDB 10.2/lib/plugin

default-character-set = utf8


[mysqldump]

default-character-set = utf8


[mysql]

default-character-set = utf8



MariaDB(MySQL) 재기동



제어판에 들어가서, "시스템 및 보안" 선택



시스템 및 보안 메뉴에서 "관리 도구"를 선택



"서비스" 메뉴를 선택



"MySQL"이라는 이름으로 된 서비스를 클릭한다. 마리아DB를 설치하여도, 서비스명은 MySQL로 되어 있다. Maria 찾아봤자 나오지 않음.



현재 구동되어 있는 서비스를 중지 시킨다.



중지가 완료되면, 시작 버튼을 클릭하여 서비스를 다시 시작한다.



변경 확인


변경이 된 것을 확인 하기 위해서, 다시 mysql -u root -p로 접근하여, c로 시작하는 변수를 확인한다.


C:\Windows\System32>mysql -u root -p

Enter password: **********

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 8

Server version: 10.2.13-MariaDB mariadb.org binary distribution


Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement


MariaDB [(none)]> show variables like 'c%';

+--------------------------+-----------------------------------------------+

| Variable_name            | Value                                         |

+--------------------------+-----------------------------------------------+

| character_set_client     | utf8                                          |

| character_set_connection | utf8                                          |

| character_set_database   | utf8                                          |

| character_set_filesystem | binary                                        |

| character_set_results    | utf8                                          |

| character_set_server     | utf8                                          |

| character_set_system     | utf8                                          |

| character_sets_dir       | C:\Program Files\MariaDB 10.2\share\charsets\ |

| check_constraint_checks  | ON                                            |

| collation_connection     | utf8_general_ci                               |

| collation_database       | utf8_general_ci                               |

| collation_server         | utf8_general_ci                               |

| completion_type          | NO_CHAIN                                      |

| concurrent_insert        | AUTO                                          |

| connect_timeout          | 10                                            |

+--------------------------+-----------------------------------------------+

15 rows in set (0.00 sec)


MariaDB [(none)]>


캐릭터셋들이 모두 utf8로 변경된 것을 확인 할 수 있다. 이제 테이블 코멘트를 다시 설정해서 깨지는지 확인을 해본다.



화면 캡쳐 내용처럼, comment가 ???에서 정상적으로 한글이 입력된 것을 확인할 수 있다.