OS:macOS Sierra 10.12.6
Mysql: 5.7.19
下載的是DMG安裝包涮雷,傻瓜式安裝更哄,添加環(huán)境變量疚鲤,修改初始密碼掂咒,進(jìn)入mysql發(fā)現(xiàn)數(shù)據(jù)庫(kù)默認(rèn)編碼是latin1才沧,不能支持中文迈喉。
在網(wǎng)上看到說(shuō)在/usr/local/mysql/support-files下面有個(gè)默認(rèn)配置文件復(fù)制成/etc/my.cnf再修改部分參數(shù)即可。但是我在這個(gè)目錄下壓根沒(méi)有找到配置文件温圆。
解決:
停止mysql服務(wù)挨摸,新建一個(gè)my.cnf
sudo vi /etc/my.cnf
配置如下:
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
character-set-server=utf8
重啟mysql服務(wù),查看編碼:
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)