Mac 에서 한글이 깨진다.
1. 현재 상황을 체크한다.
$>mysql -uroot -pxxxx
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 247
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> status
--------------
mysql Ver 14.14 Distrib 5.5.16, for osx10.6 (i386) using readline 5.1
Connection id: 247
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.16 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 8 min 12 sec
Threads: 1 Questions: 32 Slow queries: 0 Opens: 35 Flush tables: 1 Open tables: 28 Queries per second avg: 0.065
--------------
mysql> quit
$su -
password:xxxx
2. /etc/my.cnf 파일을 생성 또는 /etc/my.cnf 파일에 아래내용 추가
%vi /etc/my.cnf
[mysqld]
character-set-server=utf8
collation-server=utf8_general_ci
init_connect=SET collation_connection=utf8_general_ci
init_connect=SET NAMES utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
3. status 확인
$>mysql -uroot -pxxxx
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 247
Server version: 5.5.16 MySQL Community Server (GPL)
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> status
--------------
mysql Ver 14.14 Distrib 5.5.16, for osx10.6 (i386) using readline 5.1
Connection id: 247
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ''
Using delimiter: ;
Server version: 5.5.16 MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: utf8
Db characterset: utf8
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 8 min 12 sec
Threads: 1 Questions: 32 Slow queries: 0 Opens: 35 Flush tables: 1 Open tables: 28 Queries per second avg: 0.065
--------------
4. 테이블 생산시 기본 character set 을 utf8로 생성한다. (DEFAULT CHARSET=utf8)
mysql : create table [table_name] ( ……….. ) DEFAULT CHARSET=utf8
5. java에서 연결할때 connection url에 character encoding을 적어준다.
java : "jdbc:mysql://localhost/database_name?characterEncoding=UTF-8"
참조
http://mirwebma.tistory.com/5
http://enosent.tistory.com/31