zoukankan      html  css  js  c++  java
  • MySQL设置字符集CHARACTER SET

    本文地址:http://www.cnblogs.com/yhLinux/p/4036506.html

    my.cnf 配置文件中设置相关选项,改变为相应的character set。

    设置数据库编码(sudo vi /etc/mysql/my.cnf):

    [client]
    default-character-set = utf8
    
    [mysqld]
    character-set-server = utf8
    collation-server = utf8_general_ci

    参考资料:

      14.1.4 Character Set

      5.1.4 Server System Variables

      10.5, “Character Set Configuration”

      

      10.1 Character Set Support

      You can specify character sets at the server, database, table, and column level.

      10.1.3 Specifying Character Sets and Collations

      10.1.3.1 Server Character Set and Collation

      MySQL Server has a server character set and a server collation. These can be set at server startup on the command line or in an option file and changed at runtime.

      10.1.3.2 Database Character Set and Collation

      Every database has a database character set and a database collation.

      The character set and collation for the default database can be determined from the values of the character_set_database and collation_database system variables. The server sets these variables whenever the default database changes. If there is no default database, the variables have the same value as the corresponding server-level system variables, character_set_server and collation_server.  

    Specify character settings at server startup. To select a character set and collation at server startup, use the --character-set-server and --collation-server options. For example, to specify the options in an option file, include these lines:

    [mysqld]
    character-set-server=utf8
    collation-server=utf8_general_ci
    

    These settings apply server-wide and apply as the defaults for databases created by any application, and for tables created in those databases.

    You can force client programs to use specific character set as follows:

    [client]
    default-character-set=charset_name
    

    This is normally unnecessary. However, when character_set_system differs from character_set_server or character_set_client, and you input characters manually (as database object identifiers, column values, or both), these may be displayed incorrectly in output from the client or the output itself may be formatted incorrectly. In such cases, starting the mysql client with --default-character-set=system_character_set—that is, setting the client character set to match the system character set—should fix the problem.

    查看设置结果

    更改my.cnf之前:

    复制代码
    mysql> SHOW VARIABLES LIKE '%char%';
    +--------------------------+---------------------------------------------------------------+
    | 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/local/mysql-5.6.21-linux-glibc2.5-x86_64/share/charsets/ |
    +--------------------------+---------------------------------------------------------------+
    复制代码

     设置之后,重启mysql服务($ sudo service mysql restart):

    复制代码
    mysql> SHOW VARIABLES LIKE '%char%';
    +--------------------------+---------------------------------------------------------------+
    | 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/local/mysql-5.6.21-linux-glibc2.5-x86_64/share/charsets/ |
    +--------------------------+---------------------------------------------------------------+
    复制代码

    作者:红山玉龙
    出处:http://www.cnblogs.com/yhLinux/
    各位看官如果觉得文章对您有用的话,请猛击右下方大姆指给个推荐,让更多的朋友能够看到,以节约搜索解决方案的时间,用来做更有意义的事情o(∩_∩)o
    分享知识是快乐的,也应是自由的。欢迎各位朋友转载,请您在转载时帖上本文原文链接,谢谢!

  • 相关阅读:
    Jenkins自定义变量共享
    HTML中调用JavaScript的几种情况和规范写法
    [Python] 建 Django 项目
    [Django] Window上通过IIS发布Django网站
    [Python] 怎么把HTML的报告转换为图片,利用无头浏览器
    VMware vSphere Client
    mysql优化
    LINUX 内核的优化
    sed强大的固定替换格式
    nfs以及优化
  • 原文地址:https://www.cnblogs.com/yhLinux/p/4036506.html
Copyright © 2011-2022 走看看