美文网首页
MySQL 修改默认字符集

MySQL 修改默认字符集

作者: desirelll | 来源:发表于2017-10-30 10:32 被阅读0次

    一、检查默认字符集

    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)
    

    相关文章

      网友评论

          本文标题:MySQL 修改默认字符集

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