1. 程式人生 > >linux修改mysql字符集編碼

linux修改mysql字符集編碼

本文適用於mysql5.5 mysql5.6  其他版本未測試
#mysql -u帳號 -p密碼  登入mysql
mysql>SHOW VARIABLES LIKE 'character%'; 檢視當前字符集編碼方式

MySQL [(none)]> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | gbk |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | gbk |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.01 sec)

我這裡是gbk,現在改成utf8,反之同理
編輯/etc/my.cnf檔案
在[client]欄位下增加default-character-set = utf8
在[mysqld]欄位下增加character-set-server = utf8
在[mysql]欄位下增加default-character-set = utf8

注:在mysql欄位增加這段後,發現mysql重啟報錯,於是把這段去掉,mysql就正常了,但是後來我又繼續嘗試了次,就沒有報錯,不知道什麼問題。

修改完成後需要重啟mysql服務!
然後在#mysql -u帳號 -p密碼 登入mysql
mysql>SHOW VARIABLES LIKE 'character%';

MySQL [(none)]> SHOW VARIABLES LIKE 'character%';
+--------------------------+----------------------------------+
| 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/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.01 sec)

此時資料庫編碼改成utf8

3