• linux下的mysql乱码问题


    1,承接上一随笔,因为我用的是rmp的两种反式。

    rpm -ivh MySQL-server-4.0.14-0.i386.rpm

    rpm -ivh MySQL-client-4.0.14-0.i386.rpm

    我发现在我的linux下/etc/目录下面没有我my.cnf文件。这听说是我用了这种方式安装mysql的问题

    于是:

    [root@iZ945sgm0ugZ etc]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf
    

    并在my.cnf的[client]下加了一行default-character-set=utf8

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

    且我还在[mysqld]下面加character-set-server=utf8

    [mysqld]
    character-set-server=utf8
    

     重新启动:

    [root@iZ945sgm0ugZ etc]# /etc/init.d/mysql stop
    Shutting down MySQL...                                     [  OK  ]
    [root@iZ945sgm0ugZ etc]# /etc/init.d/mysql start
    Starting MySQL..                                           [  OK  ]
    

     乱码问题解决,ok

    2,通过mysql的sql指令来设置

     1,开启mysql服务,

    2,输入指令,查看当前编码

    mysql> show variables like 'collation_%';
    +----------------------+-------------------+
    | Variable_name        | Value             |
    +----------------------+-------------------+
    | collation_connection | utf8_general_ci   |
    | collation_database   | latin1_swedish_ci |
    | collation_server     | latin1_swedish_ci |
    +----------------------+-------------------+
    3 rows in set (0.00 sec)
    
    mysql> show variables like 'character_set_%';
    +--------------------------+----------------------------+
    | 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/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)
    mysql>  set character_set_database=utf8;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set character_set_server=utf8;
    Query OK, 0 rows affected (0.00 sec)

    mysql> set character_set_client=utf8;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set character_set_connection=utf8;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set character_set_database=utf8;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set character_set_results=utf8;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set character_set_server=utf8;
    Query OK, 0 rows affected (0.00 sec)
    mysql> set character_set_system=utf8;
    Query OK, 0 rows affected (0.01 sec)

    最终需要设置为:

    mysql> show variables like 'collation_%';
    +----------------------+-----------------+
    | Variable_name        | Value           |
    +----------------------+-----------------+
    | collation_connection | utf8_general_ci |
    | collation_database   | utf8_general_ci |
    | collation_server     | utf8_general_ci |
    +----------------------+-----------------+
    3 rows in set (0.00 sec)
    
    mysql> show variables like 'character_set_%';
    +--------------------------+----------------------------+
    | 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/ |
    +--------------------------+----------------------------+
    8 rows in set (0.00 sec)

    摘自:http://chen106106.iteye.com/blog/1639179

  • 相关阅读:
    一次简单的数据库追溯
    CI(-)框架结构
    网易有毛病,我的账号被锁了,去解锁时候又几把提示不成功,浪费劳资感情啊
    指定360浏览器内核渲染页面
    JS 拼凑字符串
    jQuery.ajax() datatype:“json" 转换失败
    html <base/>标签
    使用JExcel导出excel文件
    Java web 文件下载
    jQuery ajax 传递数组到struts2
  • 原文地址:https://www.cnblogs.com/Eddyer/p/4995056.html
Copyright © 2020-2023  润新知