본문 바로가기
SW 프로그래밍/Mariadb

MariaDB UTF8 설정

by N2info 2020. 9. 13.

먼저 MariaDB에 접속하여 DB 입출력 문자 집합을 알아봅시다. MariaDB에 root 계정으로 접속하는 명령어는 다음과 같습니다.

~$ mysql -u root -p

//접속후

show variables like 'c%';

root 계정의 암호를 입력하면 다음과 같이 MariaDB에 접속됩니다.

(처음설치후 root 암호가 미설정되었을때는 : http://magic.wickedmiso.com/104)

 

MariaDB [(none)]> show variables like 'c%';
+----------------------------------+----------------------------+
| Variable_name                    | Value                      |
+----------------------------------+----------------------------+
| character_set_client             | utf8                       |
| character_set_connection         | utf8                       |
| character_set_database           | latin1                     |
| character_set_filesystem         | binary                     |
| character_set_results            | utf8                       |
| character_set_server             | latin1                     |
| character_set_system             | utf8                       |
| character_sets_dir               | /usr/share/mysql/charsets/ |
| check_constraint_checks          | ON                         |
| collation_connection             | utf8_general_ci            |
| collation_database               | latin1_swedish_ci          |
| collation_server                 | latin1_swedish_ci          |
| column_compression_threshold     | 100                        |
| column_compression_zlib_level    | 6                          |
| column_compression_zlib_strategy | DEFAULT_STRATEGY           |
| column_compression_zlib_wrap     | OFF                        |
| completion_type                  | NO_CHAIN                   |
| concurrent_insert                | AUTO                       |
| connect_timeout                  | 10                         |
| core_file                        | OFF                        |
+----------------------------------+----------------------------+
20 rows in set (0.002 sec)

MariaDB [(none)]>

Mariadb 10.3에서는 my.cnf에 모든 설정이 저장되있지 않다.

그래서 각각에서 수정해야 한다.(참조 : https://slobell.com/blogs/38)

 

디폴트 캐릭터셋을 latin1에서 utf-8으로 변경하기 위해, 아래 3개의 파일에 캐릭터셋 설정을 추가하였다.

• /etc/my.cnf.d/client.cnf

[client]
default-character-set=utf8


• /etc/my.cnf.d/mysql-clients.cnf

[mysql]
default-character-set=utf8

[mysqldump]
default-character-set=utf8


• /etc/my.cnf.d/server.cnf

[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8

 

Mariadb 재시작

systemctl restart mariadb

Mariadb 접속후 확인

[root@localhost home]# systemctl restart mariadb
[root@localhost home]# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.5-MariaDB MariaDB Server

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               | /usr/share/mysql/charsets/ |
| check_constraint_checks          | ON                         |
| collation_connection             | utf8_general_ci            |
| collation_database               | utf8_unicode_ci            |
| collation_server                 | utf8_unicode_ci            |
| column_compression_threshold     | 100                        |
| column_compression_zlib_level    | 6                          |
| column_compression_zlib_strategy | DEFAULT_STRATEGY           |
| column_compression_zlib_wrap     | OFF                        |
| completion_type                  | NO_CHAIN                   |
| concurrent_insert                | AUTO                       |
| connect_timeout                  | 10                         |
| core_file                        | OFF                        |
+----------------------------------+----------------------------+
20 rows in set (0.001 sec)

MariaDB [(none)]>