Character Expressions, Character Sets, and Character Sequences
Each character expression has a character set and collation.
Specify the character set and collation for the CHAR expression
The character set and collation for the string expression in the SELECT 'string' statement are defined by the character_set_connection and collation_connection system variables.
The COLLATE clause can be used to specify the character set and collation of a character expression. The syntax is as follows:
[_charset_name]'string' [COLLATE collation_name]
For example:
SELECT _utf8mb4'abc' COLLATE utf8mb4_bin;
+----------------------------------+
| _utf8mb4'abc' COLLATE utf8mb4_bin |
+----------------------------------+
| abc |
+----------------------------------+
1 row in set (0.001 sec)
Character set and collation for the character expression
The seekdb statement selects the character set and collation for a character expression based on the following rules:
-
If you specify both
_charset_nameandCOLLATE collation_name, the character setcharset_nameand collationcollation_nameare used. -
If
_charset_nameis specified butCOLLATEis not, the character setcharset_nameand its default collation are used. Use theSHOW CHARACTER SETstatement to view the default collation for each character set. -
If no
_charset_nameis specified but aCOLLATE collation_nameis specified, the default character set is determined by the value of thecharacter_set_connectionsystem variable andcollation collation_name.collation_namemust be a collation supported by the default character set. -
If you do not specify
CHARACTER SETorCOLLATE, then the default character set is specified by thecharacter_set_connectionsystem variable andcollation collation_name.