<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="charset-errors">
      </a>
      12.6 Error Message Character Set
     </h2>
    </div>
   </div>
  </div>
  <p>
   This section describes how the MySQL server uses character sets
      for constructing error messages. For information about the
      language of error messages (rather than the character set), see
   <a class="xref" href="error-message-language.html" title="12.12 Setting the Error Message Language">
    Section 12.12, “Setting the Error Message Language”
   </a>
   . For general information
      about configuring error logging, see
   <a class="xref" href="error-log.html" title="7.4.2 The Error Log">
    Section 7.4.2, “The Error Log”
   </a>
   .
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="charset-errors.html#charset-errors-construction" title="Character Set for Error Message Construction">
       Character Set for Error Message Construction
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="charset-errors.html#charset-errors-disposition" title="Character Set for Error Message Disposition">
       Character Set for Error Message Disposition
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-errors-construction">
       </a>
       Character Set for Error Message Construction
      </h3>
     </div>
    </div>
   </div>
   <p>
    The server constructs error messages as follows:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The message template uses UTF-8
            (
       <code class="literal">
        utf8mb3
       </code>
       ).
      </p>
     </li>
     <li class="listitem">
      <p>
       Parameters in the message template are replaced with values
            that apply to a specific error occurrence:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: circle; ">
        <li class="listitem">
         <p>
          Identifiers such as table or column names use UTF-8
                internally so they are copied as is.
         </p>
        </li>
        <li class="listitem">
         <p>
          Character (nonbinary) string values are converted from
                their character set to UTF-8.
         </p>
        </li>
        <li class="listitem">
         <p>
          Binary string values are copied as is for bytes in the
                range
          <code class="literal">
           0x20
          </code>
          to
          <code class="literal">
           0x7E
          </code>
          , and using
          <code class="literal">
           \x
          </code>
          hexadecimal encoding for bytes outside that range. For
                example, if a duplicate-key error occurs for an attempt
                to insert
          <code class="literal">
           0x41CF9F
          </code>
          into a
          <a class="link" href="binary-varbinary.html" title="13.3.3 The BINARY and VARBINARY Types">
           <code class="literal">
            VARBINARY
           </code>
          </a>
          unique column,
                the resulting error message uses UTF-8 with some bytes
                hexadecimal encoded:
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa90726953"><div class="copy-help left">Press ⌘+C to copy</div> <div class="right"><button class="clipboard-btn" title="Copy to Clipboard"><span class="icon-clipboard"></span></button></div></div><code class="language-none">Duplicate entry 'A\xCF\x9F' for key 1</code></pre>
         </div>
        </li>
       </ul>
      </div>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-errors-disposition">
       </a>
       Character Set for Error Message Disposition
      </h3>
     </div>
    </div>
   </div>
   <p>
    An error message, once constructed, can be written by the server
        to the error log or sent to clients:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       If the server writes the error message to the error log, it
            writes it in UTF-8, as constructed, without conversion to
            another character set.
      </p>
     </li>
     <li class="listitem">
      <p>
       If the server sends the error message to a client program,
            the server converts it from UTF-8 to the character set
            specified by the
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       system variable. If
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       has a
            value of
       <code class="literal">
        NULL
       </code>
       or
       <code class="literal">
        binary
       </code>
       , no conversion occurs. No
            conversion occurs if the variable value is
       <code class="literal">
        utf8mb3
       </code>
       or
       <code class="literal">
        utf8mb4
       </code>
       ,
            either, because those character sets have a repertoire that
            includes all UTF-8 characters used in message construction.
      </p>
      <p>
       If characters cannot be represented in
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       , some
            encoding may occur during the conversion. The encoding uses
            Unicode code point values:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: circle; ">
        <li class="listitem">
         <p>
          Characters in the Basic Multilingual Plane (BMP) range
                (
          <code class="literal">
           0x0000
          </code>
          to
          <code class="literal">
           0xFFFF
          </code>
          )
                are written using
          <code class="literal">
           \
           <em class="replaceable">
            <code>
             nnnn
            </code>
           </em>
          </code>
          notation.
         </p>
        </li>
        <li class="listitem">
         <p>
          Characters outside the BMP range
                (
          <code class="literal">
           0x10000
          </code>
          to
          <code class="literal">
           0x10FFFF
          </code>
          ) are written using
          <code class="literal">
           \+
           <em class="replaceable">
            <code>
             nnnnnn
            </code>
           </em>
          </code>
          notation.
         </p>
        </li>
       </ul>
      </div>
      <p>
       Clients can set
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       to
            control the character set in which they receive error
            messages. The variable can be set directly, or indirectly by
            means such as
       <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
        <code class="literal">
         SET NAMES
        </code>
       </a>
       . For
            more information about
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       , see
       <a class="xref" href="charset-connection.html" title="12.4 Connection Character Sets and Collations">
        Section 12.4, “Connection Character Sets and Collations”
       </a>
       .
      </p>
     </li>
    </ul>
   </div>
  </div>
 </div>
 <br/>
</div>
