Mac上MySql 5.7修改默认编码为utf8

OS:macOS Sierra 10.12.6
Mysql: 5.7.19

下载的是DMG安装包,傻瓜式安装,添加环境变量,修改初始密码,进入mysql发现数据库默认编码是latin1,不能支持中文。
在网上看到说在/usr/local/mysql/support-files下面有个默认配置文件复制成/etc/my.cnf再修改部分参数即可。但是我在这个目录下压根没有找到配置文件。

解决:
停止mysql服务,新建一个my.cnf
sudo vi /etc/my.cnf
配置如下:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
重启mysql服务,查看编码:
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.7.19-macos10.12-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.00 sec)

你可能感兴趣的:(Mac上MySql 5.7修改默认编码为utf8)