리눅스(CentOS) Mysql 설치 및 UTF-8 설정하기, 한글깨짐 현상 해결

가이드문구

리눅스 설치 및 UTF-8 설정하기

  1. [root@localhost local]# yum -y install mysql*

yum 명령어를 통해 mysql을 인스톨 합니다.


설치가 완료 되었다면 Mysql 데몬을 실행합니다.

  1. [root@localhost local]# service mysqld start
  2. MySQL 데이타베이스 초기화 중: Installing MySQL system tables...
  3. OK
  4. Filling help tables...
  5. OK
  6. To start mysqld at boot time you have to copy
  7. support-files/mysql.server to the right place for your system
  8. PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
  9. To do so, start the server, then issue the following commands:
  10. /usr/bin/mysqladmin -u root password 'new-password'
  11. /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password'
  12. Alternatively you can run:
  13. /usr/bin/mysql_secure_installation
  14. which will also give you the option of removing the test
  15. databases and anonymous user created by default. This is
  16. strongly recommended for production servers.
  17. See the manual for more instructions.
  18. You can start the MySQL daemon with:
  19. cd /usr ; /usr/bin/mysqld_safe &
  20. You can test the MySQL daemon with mysql-test-run.pl
  21. cd /usr/mysql-test ; perl mysql-test-run.pl
  22. Please report any problems with the /usr/bin/mysqlbug script!
  23. [ OK ]
  24. mysqld (을)를 시작 중: [ OK ]


데몬이 정상적으로 실행 되었습니다.

Mysql 접속 테스트를 진행합니다.

※ 초기 root계정의 패스워드는 없으므로 Enter password부분은 그냥 Enter키를 눌러서 넘겨주도록 합니다.

  1. [root@localhost local]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.1.73 Source distribution
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql>


접속이 되었다면, Mysql의 인코딩 타입을 확인합니다.

  1. mysql> show variables like 'c%';
  2. +--------------------------+----------------------------+
  3. | Variable_name | Value |
  4. +--------------------------+----------------------------+
  5. | character_set_client | latin1 |
  6. | character_set_connection | latin1 |
  7. | character_set_database | latin1 |
  8. | character_set_filesystem | binary |
  9. | character_set_results | latin1 |
  10. | character_set_server | latin1 |
  11. | character_set_system | utf8 |
  12. | character_sets_dir | /usr/share/mysql/charsets/ |
  13. | collation_connection | latin1_swedish_ci |
  14. | collation_database | latin1_swedish_ci |
  15. | collation_server | latin1_swedish_ci |
  16. | completion_type | 0 |
  17. | concurrent_insert | 1 |
  18. | connect_timeout | 10 |
  19. +--------------------------+----------------------------+
  20. 14 rows in set (0.00 sec)
  21. mysql>

인코딩 확인 결과 character_set이 latin 1로 설정 되어 있습니다.

이럴 경우 한글깨짐 현상이 발생하므로 utf-8 타입으로 변경해주도록 하겠습니다.


리눅스 환경에서는 my.cnf 파일을 수정해주시면 되고, 윈도우 환경에서는 my.ini 파일을 수정하시면 되겠습니다.

리눅스에서 my.cnf 파일은 /etc/ 하위 경로에 있습니다.

  1. [root@localhost local]# vi /etc/my.cnf
  1. [client]
  2. #추가
  3. default-character-set = utf8
  4. [mysqld]
  5. #추가
  6. init_connect="SET collation_connection = utf8_general_ci"
  7. init_connect="SET NAMES utf8"
  8. default-character-set = utf8
  9. character-set-server = utf8
  10. collation-server = utf8_general_ci
  11. [mysqldump]
  12. #추가
  13. default-character-set = utf8
  14. [mysql]
  15. #추가
  16. default-character-set = utf8


인코딩 설정 변경 후 데몬을 재시작 합니다.

  1. [root@localhost local]# service mysqld restart
  2. mysqld 정지 중: [ OK ]
  3. mysqld (을)를 시작 중: [ OK ]
  4. [root@localhost local]#
  1. [root@localhost local]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.1.73 Source distribution
  6. Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> show variables like 'c%';
  12. +--------------------------+----------------------------+
  13. | Variable_name | Value |
  14. +--------------------------+----------------------------+
  15. | character_set_client | utf8 |
  16. | character_set_connection | utf8 |
  17. | character_set_database | utf8 |
  18. | character_set_filesystem | binary |
  19. | character_set_results | utf8 |
  20. | character_set_server | utf8 |
  21. | character_set_system | utf8 |
  22. | character_sets_dir | /usr/share/mysql/charsets/ |
  23. | collation_connection | utf8_general_ci |
  24. | collation_database | utf8_general_ci |
  25. | collation_server | utf8_general_ci |
  26. | completion_type | 0 |
  27. | concurrent_insert | 1 |
  28. | connect_timeout | 10 |
  29. +--------------------------+----------------------------+
  30. 14 rows in set (0.00 sec)
  31. mysql>

character_set 인코딩 타입이 utf8 설정으로 변경된 것을 확인할 수 있습니다.



작성자 소개
초이 프로필
WrapUp 블로거

초이

반려견을 좋아하고, 차를 좋아하고, 여행을 좋아하고, 맛집을 찾아 즐기는 웹 개발자 입니다^^