2012年4月24日 星期二

MySQL 設定為 utf8

設定 /etc/mysql/my.cnf

1。 在[client]區加入
default-character-set = utf8

2. 在 [mysqld]

character_set_server=utf8
collation_server=utf8_unicode_ci

3.存檔後重啟mysql
sudo service mysql restart

4. 檢查mysql是否變更為utf8
mysql -uroot -p

輸入mysql root密碼後登入mysql

mysql>

mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)

mysql>  SHOW VARIABLES LIKE 'collation_%';
+----------------------+-----------------+
| Variable_name        | Value           |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database   | utf8_unicode_ci |
| collation_server     | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)

變更成功

Ref:

沒有留言:

張貼留言