日期:2014-05-16  浏览次数:20843 次

ubuntu修改my.cnf文件导致mysql启动不了
最近在虚拟机上配置mysql,由于安装后字符集显示为
查询一下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/ |
+--------------------------+----------------------------+
先需要全部修改为utf8,根据网上提示修改mysql的启动配置文件 my.cnf
网上基本步骤为:
找到[client] 添加:
default-character-set=utf8 //默认字符集为utf8

找到[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,启动成功
再查看编码为:
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+