标签:mac mysql
1、首先检查默认安装的字符集
mysql> show variables like '%char%'; +--------------------------+--------------------------------------------------------+ | 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/local/mysql-5.6.23-osx10.8-x86_64/share/charsets/ | +--------------------------+--------------------------------------------------------+ 8 rows in set (0.00 sec)
2、查看是否有my.cnf文件在/etc/目录下
ls -al /etc/
cp /usr/local/mysql/support-files/my-default.cnf /etc/
3、修改/etc/my-default.cnf文件名为my.cnf,并修改里面的配置
cat /etc/my.cnf
ls -l /etc/my.cnf
如果改为(666)(rw- rw- rw-)则修改以后配置文件不会生效。下面详细讲解为什么不会生效。
sudo chmod 664 /etc/my.cnf
4、修改配置文件内容
vi /etc/my.cnf
[client] default-character-set=utf8
character-set-server=utf8
5、重新查看编码集
mysql> show variables like '%char%'; +--------------------------+--------------------------------------------------------+ | 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-5.6.23-osx10.8-x86_64/share/charsets/ | +--------------------------+--------------------------------------------------------+ 8 rows in set (0.00 sec)
出现问题详解:
一开始我输入的命令为
<span style="color:#ff0000;">chmod a+w /etc/my.cnf</span>这条命令的意思是my.cnf对所有用户都有写的权限,这样就变成了666了。导致我改完以后也不报错,也不生效。
直到我关闭了数据库服务,再进入数据库的时候,数据库出现一个错误
<span style="color:#ff0000;">World-writable config file '/etc/my.cnf' is ignored</span>
一下子我就懂了,打开数据库服务,修改成664后,再重启数据库,再查看编码已经成功修改。
标签:mac mysql
原文地址:http://blog.csdn.net/benjamin_whx/article/details/44747653