MySQL設定字元集CHARACTER SET

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   for   strong   

本文地址: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 = utf8collation-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=utf8collation-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/ |+--------------------------+---------------------------------------------------------------+

 

MySQL設定字元集CHARACTER SET

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.