National Character Sets and Unicode
***********************************
Improved handling of character sets is one of the features added to
MySQL in Version 4.1. This chapter explains:
* What are character sets and collations
* The multi-level default system
* New syntax in MySQL 4.1
* Affected functions and operations
* The meaning of each individual character set and collation
The features described here are as implemented in MySQL 4.1.1. (MySQL
4.1.0 has some but not all of these features, and some of them are
implemented differently.)
Character Sets and Collations in General
========================================
A *character set* is a set of symbols and encodings. A *collation* is 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 we had an alphabet with four letters: `A', `B', `a', `b'. We
give each letter a number: `A' = 0, `B' = 1, `a' = 2, `c' = 3. The
letter `A' is a symbol, the number 0 is the *encoding* for `A', and the
combination of all four letters and their encodings is a *character
set*.
than `B'.
Now, 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 a
*binary* collation.
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 letters `a' and `b' as equivalent to `A' and `B'; (2) then
compare the encodings. We call this a *case insensitive* collation.
It's a little more complex than a binary collation.
In real life, most character sets have many characters: not just `A'
and `B' but 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 case insensitivity but also accent insensitivity
(an "accent" is a mark attached to a character as in German `O"') and
multiple-character mappings (such as the rule that `O"' = `OE' in one
of the two German collations).
MySQL 4.1 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
* Allow specification of character set and collation at any level
and
collations are available, how to change their defaults, and what the
various string operators do with them.
Character Sets and Collations in MySQL
======================================
A character set always has at least one collation. It may have several
collations.
For example, character set `latin1' ("ISO-8859-1 West European") has
the following collations:
`latin1_german2_ci' German DIN-2
`latin1_swedish_ci' Swedish/Finnish
`latin1_general_ci' Multilingual
Notes:
* Two different character sets can't have the same collation.
* Each character set has one collation that is the _default
collation_. For example, the default collation for `latin1' is
`latin1_swedish_ci'.
Notice that there is a convention for collation names: They start with
the name of the character set they are associated with, they usually
include a language name, and they end with `_ci' (case insensitive),
`_cs' (case sensitive), or `_bin' (binary).
[Назад] [Содержание] [Вперед]
| Главная |