美文网首页
Windows下修改MySQL编码为utf8

Windows下修改MySQL编码为utf8

作者: 臂力棒在想 | 来源:发表于2017-04-06 18:11 被阅读1608次

    Problem

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

    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-default.ini,重命名为my.ini,添加如下配置:

    [mysqld]
    character-set-server = utf8
    
    [client]
    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)
    

    相关文章

      网友评论

          本文标题:Windows下修改MySQL编码为utf8

          本文链接:https://www.haomeiwen.com/subject/nmmqattx.html