Windows下修改MySQL编码为utf8

2020-05-27  本文已影响0人  cherishpf

Problem

Windows下安装MySQL(mysql-installer-community-5.7.29.0.msi)后,默认编码不全是utf8。

mysql> show variables like '%char%';
+--------------------------+---------------------------------------------------------+
| Variable_name            | Value                                                   |
+--------------------------+---------------------------------------------------------+
| character_set_client     | gbk                                                     |
| character_set_connection | gbk                                                     |
| character_set_database   | utf8                                                    |
| character_set_filesystem | binary                                                  |
| character_set_results    | gbk                                                     |
| character_set_server     | utf8                                                    |
| character_set_system     | utf8                                                    |
| character_sets_dir       | D:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set, 1 warning (0.01 sec)

Solution

进入MySQL安装的目录(如果是默认安装的话则my.ini文件路径是:C:\ProgramData\MySQL\MySQL Server 5.7),打开my.ini(用记事本或Notepad++),添加如下配置:

[mysqld]
character-set-server = utf8

[mysql]
default-character-set = utf8

重启MySQL服务(右键计算机 > 管理 > 服务和应用程序 > 服务 > 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       | D:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
+--------------------------+---------------------------------------------------------+
8 rows in set, 1 warning (0.01 sec)

</article>

参考文章:https://www.jianshu.com/p/f4a564179107

上一篇下一篇

猜你喜欢

热点阅读