10bet网址
MySQL 5.7 Reference Manual
相关的文档10bet官方网站 Download this Manual
PDF (US Ltr)- 36.3Mb
PDF (A4)- 36.3Mb
Man Pages (TGZ)- 235.6Kb
Man Pages (Zip)- 347.2Kb
Info (Gzip)- 3.3Mb
Info (Zip)- 3.3Mb
Excerpts from this Manual

MySQL 5.7 Reference Manual/Character Sets, Collations, Unicode/ Character Sets and Collations in General

10.1 Character Sets and Collations in General

Acharacter setis a set of symbols and encodings. Acollationis a set of rules for comparing characters in a character set. Let's make the distinction clear with an example of an imaginary character set.

Suppose that we have an alphabet with four letters:A,B,a,b. We give each letter a number:A= 0,B= 1,a= 2,b= 3. The letterAis a symbol, the number 0 is theencodingforA, and the combination of all four letters and their encodings is acharacter set.

Suppose that we want to compare two string values,AandB. The simplest way to do this is to look at the encodings: 0 forAand 1 forB. Because 0 is less than 1, we sayAis less thanB. What we've just done is apply a collation to our character set. The collation is a set of rules (only one rule in this case):compare the encodings.We call this simplest of all possible collations abinarycollation.

But what if we want to say that the lowercase and uppercase letters are equivalent? Then we would have at least two rules: (1) treat the lowercase lettersaandbas equivalent toAandB; (2) then compare the encodings. We call this acase-insensitivecollation. It is a little more complex than a binary collation.

In real life, most character sets have many characters: not justAandBbut whole alphabets, sometimes multiple alphabets or eastern writing systems with thousands of characters, along with many special symbols and punctuation marks. Also in real life, most collations have many rules, not just for whether to distinguish lettercase, but also for whether to distinguish accents (anaccentis a mark attached to a character as in GermanÖ), and for multiple-character mappings (such as the rule thatÖ=OEin one of the two German collations).

MySQL can do these things for you:

  • Store strings using a variety of character sets.

  • Compare strings using a variety of collations.

  • Mix strings with different character sets or collations in the same server, the same database, or even the same table.

  • Enable specification of character set and collation at any level.

To use these features effectively, you must know what character sets and collations are available, how to change the defaults, and how they affect the behavior of string operators and functions.