zoukankan      html  css  js  c++  java
  • Linux下MySQL 5.5的修改字符集编码为UTF8(彻底解决中文乱码问题)

    http://www.ha97.com/5359.html

    PS:昨天一同事遇到mysql 5.5中文乱码问题,找我解决。解决了,有个细节问题网上没人说,我就总结一下。

    一、登录MySQL查看用SHOW VARIABLES LIKE ‘character%’;下字符集,显示如下:

    +--------------------------+----------------------------+
    | 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/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    请读者点击原网址链接,这里我没有复制完全。谢谢,个人转载
    character_set_database和character_set_server的默认字符集还是latin1。

    二、最简单的完美修改方法,修改mysql的my.cnf文件中的字符集键值(注意配置的字段细节):

    1、在[client]字段里加入default-character-set=utf8,如下:

    [client]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    default-character-set=utf8

    2、在[mysqld]字段里加入character-set-server=utf8,如下:

    [mysqld]
    port = 3306
    socket = /var/lib/mysql/mysql.sock
    character-set-server=utf8

    3、在[mysql]字段里加入default-character-set=utf8,如下:

    [mysql]
    no-auto-rehash
    default-character-set=utf8

    修改完成后,service mysql restart重启mysql服务就生效。注意:[mysqld]字段与[mysql]字段是有区别的。这点在网上没人反馈过。

    使用SHOW VARIABLES LIKE ‘character%’;查看,发现数据库编码全已改成utf8。

    +--------------------------+----------------------------+
    | 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/ |
    +--------------------------+----------------------------+


  • 相关阅读:
    用css3弹性盒子模型实现九宫格布局
    css布局之左中右结构总结
    内联块inline-block的垂直间隙问题
    Jquery选择器 讲解
    U大师装系统
    陈伟:软件趋势——云物移大智
    asp网站发布步骤总结
    MYfirst
    ASP.net 利用From实现上传文件
    【ASP.NET Core CentOS 发布】(四)在CentOS上安装.NET Core运行时、部署到CentOS
  • 原文地址:https://www.cnblogs.com/robbychan/p/3786530.html
Copyright © 2011-2022 走看看