MySQL Character Set

Source: Internet
Author: User

MySQL character set includes two concepts: character set (character) and collation. Character set is used to define the rules for MySQL to store strings. The collation defines the method for comparing strings. There is a one-to-many> relationship between strings and proofreading rules. Run the show collation like 'gbk' command to view the checking rules. Use: Show character set to view all available character sets.
Naming Conventions for proofreading rules: they start with their relevant character sets, usually including a language name, with a _ Ci (Case Insensitive), _ CS (case sensitive) or _ Bin (binary, that is, the comparison is based on the character set encoding value and is not related to language) ends.
MySQL's Character Set and verification rules have four default values: Server-level, database-level, table-level, and field-level.
Server character set (default: Latin1 as server Character Set ):
Set in my. CNF: default-character-set = GBK
Specify mysqld -- default-character-set = GBK when the server is started.
When compiling, set:./configure -- With-character = GBK
Run the show variables like 'character _ set_server 'command to view the character set and verification rules used by the current server.
The character set and collation rules of the database are specified when the database is created. You can also use the 'alter table' command to modify the database after the database is created. It should be noted that modifying the database character set does not change the characters of existing data.
Set. Command: Show variables like 'chaacter _ set_database '; view the character set currently used by the database.
Table Character Set and calibration value: the character set of the table can be specified when the table is in the same house or can be modified using the alter table command. Similarly, if there are already records in the table, the Modified Character Set does not include the original records.
Column Character Set and Proofreading: MySQL also supports Defining column-level character sets. You can define character sets and proofreading rules for different fields in the same table.
Link Character Set and verification rules
In actual application access, character sets and collation settings between the client and the server also exist.
For client-to-server interaction, MySQL provides three different parameters: character_set_client, character_set_connection, and character_set_results, representing the client, link, and response respectively.
The character set of the result. Generally, the three character sets must be the same to ensure that the data written by the user can be correctly read.
Command: Set names ***; can be used to modify the values of these three parameters at the same time. To use this method to modify the character set and verification rules of a link, you need to apply this command every time you connect to the database.
In the configuration file my. CNF, after the server is started by setting default-character-set = GBK, all links are linked using the GBK character set by default.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.