1. 程式人生 > >MySQL修改字符集為utf8

MySQL修改字符集為utf8

檢視資料庫字符集:show variables like “%character%”;

修改前:

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

修改mysql配置檔案my.cnf(如沒有my.cnf則找到mysql.cnf):

在[mysqld]欄位里加入character-set-server=utf8,如下:

[mysqld] port = 3306 socket = /var/lib/mysql/mysql.sockcharacter-set-server=utf8

修改完成後,service mysql restart重啟mysql服務,再次檢視字符集

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

修改完成。