zoukankan      html  css  js  c++  java
  • centos 修改 mysql 字符集

    客户提供了 mysql 的环境,但是不支持中文,通过以下命令查看了 mysql 的字符集

    mysql> show variables like 'character_set%';

    显示如下:

    +--------------------------+----------------------------+  
    | Variable_name            | Value                      |  
    +--------------------------+----------------------------+  
    | character_set_client     | latin1                     |  
    | character_set_connection | latin1                     |  
    | character_set_database   | latin1                     |  
    | character_set_filesystem | binary                     |  
    | character_set_results    | latin1                     |  
    | character_set_server     | latin1                     |  
    | character_set_system     | utf8                       |  
    | character_sets_dir       | /usr/share/mysql/charsets/ |  
    +--------------------------+----------------------------+ 

    为了让 mysql 支持中文,需要把字符集改变成 utf8 。

    方法如下:

    1. 打开 etc/my.cnf

    2. 修改成如下内容,保存

    [client]  
    port=3306  
    socket=/var/lib/mysql/mysql.sock  
    default-character-set=utf8  
      
    [mysqld]  
    datadir=/var/lib/mysql  
    socket=/var/lib/mysql/mysql.sock  
    user=mysql  
    # Disabling symbolic-links is recommended to prevent assorted security risks  
    symbolic-links=0  
    character-set-server=utf8  
      
    [mysql]  
    no-auto-rehash  
    default-character-set=utf8  
      
    [mysqld_safe]  
    log-error=/var/log/mysqld.log  
    pid-file=/var/run/mysqld/mysqld.pid 

    3. 重启 mysql 服务

    service mysqld restart

    再次查看 mysql 编码,已经更新成如下信息

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

      

  • 相关阅读:
    windows 10中出现“某个应用导致****文件的默认应用设置出现问题”
    全站仪数据修正为南方cass可识别数据
    用顺序表建立一个简单的可以插入删除的学生成绩管理表
    头插法与尾插法建立单链表
    修改windows下的服务名称
    批处理同时执行多个Ant文件
    Informix数据库中的TO_DATE函数
    Ant发送邮件email
    数据库视图
    Hibernate的三种状态的解释
  • 原文地址:https://www.cnblogs.com/onepixel/p/9154884.html
Copyright © 2011-2022 走看看