mysql 字符集
Character Set and Collation
Every character string literal has a character set and a collation.
For the simple statement SELECT ', the string has the connection default character set and collation defined by the string'character_set_connection and collation_connection system variables.
A character string literal may have an optional character set introducer and COLLATE clause, to designate it as a string that uses a particular character set and collation:
[_charset_name]'string' [COLLATE collation_name]
The _ expression is formally called an introducer. It tells the parser, “the string that follows uses character set charset_namecharset_name.” An introducer does not change the string to the introducer character set like CONVERT() would do. It does not change the string value, although padding may occur. The introducer is just a signal. See Section 10.3.8, “Character Set Introducers”.
Examples:
SELECT 'abc';
SELECT _latin1'abc';
SELECT _binary'abc';
SELECT _utf8'abc' COLLATE utf8_danish_ci;
Character set introducers and the COLLATE clause are implemented according to standard SQL specifications.
MySQL determines the character set and collation of a character string literal in the following manner:
-
If both
_charset_nameandCOLLATEare specified, character setcollation_namecharset_nameand collationcollation_nameare used.collation_namemust be a permitted collation forcharset_name. -
If
_charset_nameis specified butCOLLATEis not specified, character setcharset_nameand its default collation are used. To see the default collation for each character set, use theSHOW CHARACTER SETstatement or query theINFORMATION_SCHEMACHARACTER_SETStable. -
If
_charset_nameis not specified butCOLLATEis specified, the connection default character set given by thecollation_namecharacter_set_connectionsystem variable and collationcollation_nameare used.collation_namemust be a permitted collation for the connection default character set. -
Otherwise (neither
_charset_namenorCOLLATEis specified), the connection default character set and collation given by thecollation_namecharacter_set_connectionandcollation_connectionsystem variables are used.
- 点赞
- 收藏
- 关注作者
评论(0)