轉(zhuǎn)載自廖雪峰-->在Mac或Linux上广鳍,需要編輯MySQL的配置文件,把數(shù)據(jù)庫(kù)默認(rèn)的編碼全部改為UTF-8吓妆。MySQL的配置文件默認(rèn)存放在/etc/my.cnf
或者/etc/mysql/my.cnf:
[client]
default-character-set = utf8
[mysqld]
default-storage-engine = INNODB
character-set-server = utf8
collation-server = utf8_general_c
重啟MySQL后赊时,可以通過(guò)MySQL的客戶端命令行檢查編碼:
sudo service mysql restart
mysql -u root -p
Enter password:
Welcome to the MySQL monitor...
...
mysql> show variables like '%char%';+--------------------------+--------------------------------------------------------+| 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/local/mysql-5.1.65-osx10.6-x86_64/share/charsets/ |+--------------------------+--------------------------------------------------------+8 rows in set (0.00 sec)
看到utf8
字樣就表示編碼設(shè)置正確。