zoukankan      html  css  js  c++  java
  • mysql 字符集设置方法

    php 5.6,
    mysql 5.5
    /etc/my.cnf

    (1) 最简单的修改方法,就是修改mysql的my.ini文件中的字符集键值,

    如 default-character-set = utf8
    character_set_server = utf8

    修改完后,重启mysql的服务,service mysql restart

    使用 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 | D:"mysql-5.0.37"share"charsets" |
    +--------------------------+---------------------------------+

    (2) 还有一种修改mysql默认字符集的方法,就是使用mysql的命令

    SET character_set_client = utf8;
    SET character_set_connection = utf8;
    SET character_set_database = utf8;
    SET character_set_results = utf8;
    SET character_set_server = utf8;

    SET collation_connection = utf8;
    SET collation_database = utf8;
    SET collation_server = utf8;

    一般就算设置了表的mysql默认字符集为utf8并且通过UTF-8编码发送查询,你会发现存入数据库的仍然是乱码。问题就出在这个connection连接层上。解决方法是在发送查询前执行一下下面这句:

    SET NAMES 'utf8';

    它相当于下面的三句指令:

    SET character_set_client = utf8;
    SET character_set_results = utf8;
    SET character_set_connection = utf8;

  • 相关阅读:
    Java调用getResource方法获取文件路径乱码
    Java时间格式转换
    java——枚举类型通过反射获取属性值并合成Map进行对比取值
    JXLS问题
    elementUI——select 根据传入的ID值选中选项
    强、软、弱、虚四种引用的区别
    frp + ssl证书 + 宝塔面板 实现 https 访问内网可道云
    ReentrantLock 公平锁和非公平锁的区别
    Stream流式计算
    四大函数式接口
  • 原文地址:https://www.cnblogs.com/zjhblogs/p/5584346.html
Copyright © 2011-2022 走看看