自从上次重装系统之后,装好 MySQL 5.7 之后就没管过,今天发现居然存储不了中文,使用 show variables like 'char%'; 查询发现居然不是 utf8 而是 Latin 编码,怪不得不支持中文。

mysql> SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';
+--------------------------+---------------------------------------------------------+
| Variable_name            | Value                                                   |
+--------------------------+---------------------------------------------------------+
| character_set_client     | utf8mb4                                                 |
| character_set_connection | utf8mb4                                                 |
| character_set_database   | latin1                                                  |
| character_set_filesystem | binary                                                  |
| character_set_results    | utf8mb4                                                 |
| character_set_server     | latin1                                                  |
| character_set_system     | utf8                                                    |
| character_sets_dir       | C:\Program Files\MySQL\MySQL Server 5.7\share\charsets\ |
| collation_connection     | utf8mb4_general_ci                                      |
| collation_database       | latin1_swedish_ci                                       |
| collation_server         | latin1_swedish_ci                                       |
+--------------------------+---------------------------------------------------------+
11 rows in set, 1 warning (0.00 sec)

怒修改,编辑 my.ini 文件,文件位置 C:\ProgramData\MySQL\MySQL Server 5.7\my.ini 当然可以在 Windows 服务中找到,添加部分如下

阅读更多...