摘要:本文適用于mysql5.5 mysql5.6? 其他版本未測(cè)試 mysql -u帳號(hào) -p密碼? 登錄mysql mysql>SHOW VARIABLES LIKE 'character%'; 查看當(dāng)前字符集編碼方式 MySQL [(none)]> SHOW VARIABLES LIKE 'cha
本文適用于mysql5.5 mysql5.6 ?其他版本未測(cè)試
mysql -u帳號(hào)?-p密碼 ?登錄mysql
mysql>SHOW VARIABLES LIKE 'character%';查看當(dāng)前字符集編碼方式
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秦叛,現(xiàn)在改成utf8,反之同理
編輯/etc/my.cnf文件
在[client]字段下增加default-character-set = utf8
在[mysqld]字段下增加character-set-server = utf8
在[mysql]字段下增加default-character-set = utf8
注:在mysql字段增加這段后撒璧,發(fā)現(xiàn)mysql重啟報(bào)錯(cuò)床蜘,于是把這段去掉堡牡,mysql就正常了欺缘,但是后來(lái)我又繼續(xù)嘗試了次,就沒有報(bào)錯(cuò)现斋,不知道什么問(wèn)題府树。
修改完成后需要重啟mysql服務(wù)俐末!
然后在#mysql -u帳號(hào)?-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)
此時(shí)數(shù)據(jù)庫(kù)編碼改成utf8
用云棲社區(qū)APP,舒服~