ubuntu修改my.cnf文件導致mysql啟動不了的問題
最近在虛擬機上配置mysql,由於安裝後字符集顯示為
查詢一下show variables like 'character%';
+--------------------------+----------------------------+
| Variable_name | Value | www.2cto.com
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
先需要全部修改為utf8,根據網上提示修改mysql的啟動配置文件 my.cnf
網上基本步驟為:
找到[client] 添加:
default-character-set=utf8 //默認字符集為utf8
www.2cto.com
找到[mysqld] 添加:
//默認字符集為utf8
default-character-set=utf8
//設定連接mysql數據庫時使用utf8編碼,以讓mysql數據庫為utf8運行
init_connect='SET NAMES utf8'
可是我根據這樣修改後啟動mysql服務報錯,啟動不了
在網上試了多種解決辦法,都沒有解決,
最後找到一個方法,可以解決,如下:
其他的還跟上面一樣,只有在[mysqld]下面添加的
default-character-set=utf8
改為
character-set-server = utf8
重新啟動mysql,啟動成功
再查看編碼為: www.2cto.com
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+