Specifying Character Sets and Collations
775
Query OK, 0 rows affected (0.00 sec)
mysql>
SELECT HEX('à\n'), HEX(_latin1'à\n');
+------------+-------------------+
| HEX('à\n') | HEX(_latin1'à\n') |
+------------+-------------------+
| E05C6E | E05C6E |
+------------+-------------------+
1 row in set (0.04 sec)
Here,
character_set_connection
[442]
is
sjis
, a character set in which the sequence of “
à
”
followed by “
\
” (hex values
05
and
5C
) is a valid multi-byte character. Hence, the first two bytes of the
string are interpreted as a single
sjis
character, and the “
\
” is not interpreted as an escape character.
The following “
n
” (hex value
6E
) is not interpreted as part of an escape sequence. This is true even for
the second string; the introducer of
_latin1
does not affect escape processing.
10.1.3.6. National Character Set
Standard SQL defines
NCHAR
or
NATIONAL CHAR
as a way to indicate that a
CHAR
column should use
some predefined character set. MySQL 5.0 uses
utf8
as this predefined character set. For example,
these data type declarations are equivalent:
CHAR(10) CHARACTER SET utf8
NATIONAL CHARACTER(10)
NCHAR(10)
As are these:
VARCHAR(10) CHARACTER SET utf8
NATIONAL VARCHAR(10)
NCHAR VARCHAR(10)
NATIONAL CHARACTER VARYING(10)
NATIONAL CHAR VARYING(10)
You can use
N'literal'
(or
n'literal'
) to create a string in the national character set. These
statements are equivalent:
SELECT N'some text';
SELECT n'some text';
SELECT _utf8'some text';
For information on upgrading character sets to MySQL 5.0 from versions prior to 4.1, see the MySQL
3.23, 4.0, 4.1 Reference Manual.
10.1.3.7. Examples of Character Set and Collation Assignment
The following examples show how MySQL determines default character set and collation values.
Example 1: Table and Column Definition
CREATE TABLE t1
(
c1 CHAR(10) CHARACTER SET latin1 COLLATE latin1_german1_ci
) DEFAULT CHARACTER SET latin2 COLLATE latin2_bin;
Here we have a column with a
latin1
character set and a
latin1_german1_ci
collation. The
definition is explicit, so that is straightforward. Notice that there is no problem with storing a
latin1
column in a
latin2
table.
Example 2: Table and Column Definition
CREATE TABLE t1
(
c1 CHAR(10) CHARACTER SET latin1
) DEFAULT CHARACTER SET latin1 COLLATE latin1_danish_ci;
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 ...