본문 바로가기

Development/Web & Server

[MYSQL] utf-8 설정하기~!

한글로 입력하니 ??? 이런씩으로 입력이 되어 확인해보니 Mysql 이 character set이 전부 utf-8로 되어있지 않았다. 

그래서 utf-8로 설정을 바꾸었다.


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

| 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/ |

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



1./etc/my.cnf 파일 수정


[mysql]

default-character-set = utf8


[mysqld]

character-set-client-handshake=FALSE

init_connect="SET collation_connection = utf8_general_ci"

init_connect="SET NAMES utf8"

character-set-server = utf8

collation-server = utf8_general_ci

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


[client]

default-character-set = utf8


[mysqldump]

default-character-set = utf8


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid


2. mysqld resatrt

sudo service mysqld restart


3. 확인

mysql> 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/ |

| 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                         |

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