MySQL 修改默认字符集

2017-10-30  本文已影响0人  desirelll

一、检查默认字符集

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.7.19-macos10.12-x86_64/share/charsets/ |
+--------------------------+-----------------------------------------------------------+
8 rows in set (0.00 sec)

character_set_database和character_set_server依然是latin1的字符集,也就是说mysql后续创建的表都是latin1字符集的,不是utf8,会造成一些麻烦。所以有必要修改my.cnf,在修改my.cnf之前一定要关闭mysql进程,不然会遇到mysql的sock不能连接的问题。

二、关闭 mysqld 后台进程


三、修改 mysql 配置文件

sudo vi /etc/my.cnf
添加如下内容

[client]
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.01 sec)
上一篇下一篇

猜你喜欢

热点阅读