• centos(linux) 下mysql 编码设置 乱码


    关键词:cent os(linux),MySQL,乱码

    cent os在上安装mysql client和server之后,出现乱码,不得不修改编码。

    环境:cent os、mysql

    注意:关于utf8和gbk的区别详细见:linux中文乱码问题解决办法 ,下面的配置中根据自己要求选择两种编码。

    解决步骤:

    1. 找到mysql的配置文件,拷贝到etc目录下,第一步很重要

    使用find命令查找cnf文件。记得不要去找my.cnf因为它不一定存在,而应该找*.cnf。
    [root@linuxserver classes] find / -iname *.cnf -print
    /root/Desktop/mysql-5.0.56/mysql-test/std_data/ndb_config_mycnf1.cnf
    /root/Desktop/mysql-5.0.56/mysql-test/std_data/bug15328.cnf
    /root/Desktop/mysql-5.0.56/mysql-test/std_data/ndb_config_mycnf2.cnf
    /etc/my.cnf
    /etc/pki/tls/openssl.cnf
    /usr/share/mysql/my-medium.cnf
    /usr/share/mysql/my-large.cnf
    /usr/share/mysql/my-small.cnf
    /usr/share/mysql/my-huge.cnf
    /usr/share/mysql/my-innodb-heavy-4G.cnf
    /usr/share/doc/MySQL-server-community-5.0.92/my-medium.cnf
    /usr/share/doc/MySQL-server-community-5.0.92/my-large.cnf
    /usr/share/doc/MySQL-server-community-5.0.92/my-small.cnf
    /usr/share/doc/MySQL-server-community-5.0.92/my-huge.cnf
    /usr/share/doc/MySQL-server-community-5.0.92/my-innodb-heavy-4G.cnf

    找到之后,复制一个出来
     cp /usr/share/doc/MySQL-server-community-5.0.92/my-large.cnf   /etc/my.cnf

    2. 打开my.cnf修改编码

     vi /etc/my.cnf

    在[mysqld]下添加
    default-character-set=utf8

    在[client]下添加
    default-character-set=utf8

    3. 重启mysql

    根据你安装mysql的方式的不同,采用不用的命令来重启你的mysql。如果你配置过使用mysqld自启动方式,可以执行

     /etc/rc.d/init.d/mysql restart

    mysql配置成系统服务的方式,执行
     service mysqld restert

    4.登录mysql看看修改成功否

    show variables like 'character%';
    +--------------------------+----------------------------+
    | 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/share/mysql/charsets/ |

  • 相关阅读:
    数据库系列之T-SQL(系统内置函数)
    数据库系列之T-SQL(存储过程)
    数据库系列之T-SQL(作业与维护计划)
    数据库系列之T-SQL(触发器)
    数据库系列之T-SQL(事务)
    数据库系列之T-SQL(基础)
    数据库系列之查询(5)
    Nginx + Apache 公用80端口的配置
    客户端putty, xshell连接linux中vim的小键盘问题
    配置EPEL YUM源
  • 原文地址:https://www.cnblogs.com/zhouwenwu/p/2306429.html
Copyright © 2020-2023  润新知