This section describes how the 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.2, “Setting the Error Message Language”.
As of MySQL 5.5, the server constructs error messages using
UTF-8 and returns them to clients in the character set specified
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
0x7E, and using
hex encoding for bytes outside that range. For example,
if a duplicate-key error occurs for an attempt to insert
0x41CF9F into a
VARBINARY unique column,
the resulting error message uses UTF-8 with some bytes
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
no conversion occurs. No conversion occurs if the variable value
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
Characters outside the BMP range (
0x10FFFF) are written using
Clients can set
control the character set in which they receive error messages.
The variable can be set directly, or indirectly by means such as
NAMES. For more information about
Section 10.1.4, “Connection Character Sets and Collations”.
Prior to MySQL 5.5, the server constructs error messages and returns them to clients as follows:
The message template has the character set associated with
the error message language. For example, English, Korean,
and Russian messages use
Parameters in the message template are replaced with values
that apply to a specific error occurrence. These parameters
use their own character set. Identifiers such as table or
column names use UTF-8. Data values retain their character
set. For example, in the following duplicate-key message,
' has the
character set of the table column associated with key 1:
Duplicate entry '
xxx' for key1
The preceding method of error-message construction can result in messages that contain a mix of character sets unless all items involved contain only ASCII characters.
For MySQL 5.5 and higher, the encoding that occurs during the
returning error messages to clients can result in different
message content compared to earlier versions. For example, if an
error occurs for an attempt to drop a table named
ペ (KATAKANA LETTER PE) and
character_set_results is a
character set such as
latin1 that does not
contain that character, the resulting message sent to the client
has an encoded table name:
ERROR 1051 (42S02): Unknown table '\30DA'
Before MySQL 5.5, the name is not encoded:
ERROR 1051 (42S02): Unknown table 'ペ'