Every table has a table character set and a table collation.
The CREATE TABLE
and
ALTER TABLE
statements have
optional clauses for specifying the table character set and
collation:
CREATE TABLEtbl_name
(column_list
) [[DEFAULT] CHARACTER SETcharset_name
] [COLLATEcollation_name
]] ALTER TABLEtbl_name
[[DEFAULT] CHARACTER SETcharset_name
] [COLLATEcollation_name
]
Example:
CREATE TABLE t1 ( ... ) CHARACTER SET latin1 COLLATE latin1_danish_ci;
MySQL chooses the table character set and collation in the following manner:
If both
CHARACTER SET
andX
COLLATE
are specified, character setY
X
and collationY
are used.If
CHARACTER SET
is specified withoutX
COLLATE
, character setX
and its default collation are used. To see the default collation for each character set, use theSHOW COLLATION
statement.If
COLLATE
is specified withoutY
CHARACTER SET
, the character set associated withY
and collationY
are used.Otherwise, the database character set and collation are used.
The table character set and collation are used as default values for column definitions if the column character set and collation are not specified in individual column definitions. The table character set and collation are MySQL extensions; there are no such things in standard SQL.