MAC安装mysql后不能显示中文,参考了网上给的解决办法,有的没有成功,还导致无法启动mysql server.折腾一番终于解决了,记录下来。
首先打开终端,登陆:
mysql -uroot -p
输入密码后,查看数据库编码:
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/ |
+--------------------------+----------------------------+
CTRL+D退出mysql,打开系统偏好设置,关闭mysql服务。
然后查看mysql安装位置:
which mysql
默认安装在/usr/local/mysql/bin/mysql,进入mysql配置文件目录:
cd /usr/local/mysql/support-files
复制任意.cnf文件到etc目录下,新复制的文件名为my.cnf:
sudo cp my-medium.cnf /etc/my.cnf
打开my.cnf,一次做如下修改:
- 在[client]字段下加上
default-character-set=utf8
- 在[mysqld]字段下加上
character-set-server=utf8
- 在[mysql]字段下加上
default-character-set=utf8
重启mysql服务,重新查看数据库编码SHOW VARIABLES LIKE 'character%';
,显示如下:
mysql> 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-5.5.47-osx10.8-x86_64/share/charsets/ |
+--------------------------+--------------------------------------------------------+
8 rows in set (0.00 sec)
至此,修改成功
如果修改后登录mysql出现下面错误:
ypdeMacBook-Pro:support-files yp$ mysql -uroot -p
mysql: [ERROR] unknown variable 'sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'
删除/etc/my.cnf中的:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES