Specifying Character Sets and Collations
770
• Two different character sets cannot 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
. The output for
SHOW CHARACTER SET
indicates which collation
is the default for each displayed character set.
• There is a convention for collation names: They start with the name of the character set with which
they are associated, they usually include a language name, and they end with
_ci
(case insensitive),
_cs
(case sensitive), or
_bin
(binary).
In cases where a character set has multiple collations, it might not be clear which collation is most
suitable for a given application. To avoid choosing the wrong collation, it can be helpful to perform
some comparisons with representative data values to make sure that a given collation sorts values the
way you expect.
Collation-Charts.Org
is a useful site for information that shows how one collation compares to another.
10.1.3. Specifying Character Sets and Collations
There are default settings for character sets and collations at four levels: server, database, table,
and column. The description in the following sections may appear complex, but it has been found in
practice that multiple-level defaulting leads to natural and obvious results.
CHARACTER SET
is used in clauses that specify a character set.
CHARSET
can be used as a synonym
for
CHARACTER SET
.
Character set issues affect not only data storage, but also communication between client programs and
the MySQL server. If you want the client program to communicate with the server using a character
set different from the default, you'll need to indicate which one. For example, to use the
utf8
Unicode
character set, issue this statement after connecting to the server:
SET NAMES 'utf8';
For more information about character set-related issues in client/server communication, see
Section 10.1.4, “Connection 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.
Initially, the server character set and collation depend on the options that you use when you start
mysqld
. You can use
--character-set-server
[403]
for the character set. Along with it,
you can add
--collation-server
[403]
for the collation. If you don't specify a character set,
that is the same as saying
--character-set-server=latin1
[403]
. If you specify only a
character set (for example,
latin1
) but not a collation, that is the same as saying
--character-
set-server=latin1
[403]
--collation-server=latin1_swedish_ci
[403]
because
latin1_swedish_ci
is the default collation for
latin1
. Therefore, the following three commands all
have the same effect:
shell>
mysqld
shell>
mysqld --character-set-server=latin1
shell>
mysqld --character-set-server=latin1 \
--collation-server=latin1_swedish_ci
One way to change the settings is by recompiling. If you want to change the default server
character set and collation when building from sources, use:
--with-charset
[122]
and
--with-
collation
[122]
as arguments for
configure
. For example:
shell>
./configure --with-charset=latin1
Or:
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...