This section describes how the MySQL server uses character sets for constructing error messages and returning them to clients. For information about the language of error messages (rather than the character set), see Section 10.11, “Setting the Error Message Language”. For general information about configuring error logging, see Section 5.4.2, “The Error Log”.
The server constructs error messages using UTF-8 and returns them
to clients in the character set specified by the
variable. Clients can set
character_set_results to control
the character set in which they receive error messages. The
variable can be set directly, or indirectly by means such as
SET NAMES. For more information
Section 10.4, “Connection Character Sets and Collations”.
The server constructs error messages as follows:
The message template uses UTF-8.
Parameters in the message template are replaced with values that apply to a specific error occurrence:
Identifiers such as table or column names use UTF-8 internally so they are copied as is.
Character (nonbinary) string values are converted from their character set to UTF-8.
Binary string values are copied as is for bytes in the range
0x7E, and using
\xhexadecimal encoding for bytes outside that range. For example, if a duplicate-key error occurs for an attempt to insert
VARBINARYunique column, the resulting error message uses UTF-8 with some bytes hexadecimal encoded:
Duplicate entry 'A\xC3\x9F' for key 1
To return a message to the client after it has been constructed,
the server converts it from UTF-8 to the character set specified
system variable. If
character_set_results has a value
conversion occurs. No conversion occurs if the variable value is
utf8, either, because that matches the original
error message character set.
For characters that cannot be represented in
encoding may occur during the conversion. The encoding uses
Unicode code point values:
Characters in the Basic Multilingual Plane (BMP) range (
0xFFFF) are written using
Characters outside the BMP range (
0x10FFFF) are written using