<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="charset-unicode">
      </a>
      12.9 Unicode Support
     </h2>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="charset-unicode-utf8mb4.html">
       12.9.1 The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-utf8mb3.html">
       12.9.2 The utf8mb3 Character Set (3-Byte UTF-8 Unicode Encoding)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-utf8.html">
       12.9.3 The utf8 Character Set (Deprecated alias for utf8mb3)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-ucs2.html">
       12.9.4 The ucs2 Character Set (UCS-2 Unicode Encoding)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-utf16.html">
       12.9.5 The utf16 Character Set (UTF-16 Unicode Encoding)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-utf16le.html">
       12.9.6 The utf16le Character Set (UTF-16LE Unicode Encoding)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-utf32.html">
       12.9.7 The utf32 Character Set (UTF-32 Unicode Encoding)
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="charset-unicode-conversion.html">
       12.9.8 Converting Between 3-Byte and 4-Byte Unicode Character Sets
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <p>
   The Unicode Standard includes characters from the Basic
      Multilingual Plane (BMP) and supplementary characters that lie
      outside the BMP. This section describes support for Unicode in
      MySQL. For information about the Unicode Standard itself, visit
      the
   <a class="ulink" href="http://www.unicode.org/" target="_blank">
    Unicode Consortium
      website
   </a>
   .
  </p>
  <p>
   BMP characters have these characteristics:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Their code point values are between 0 and 65535 (or
      <code class="literal">
       U+0000
      </code>
      and
      <code class="literal">
       U+FFFF
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      They can be encoded in a variable-length encoding using 8, 16,
          or 24 bits (1 to 3 bytes).
     </p>
    </li>
    <li class="listitem">
     <p>
      They can be encoded in a fixed-length encoding using 16 bits
          (2 bytes).
     </p>
    </li>
    <li class="listitem">
     <p>
      They are sufficient for almost all characters in major
          languages.
     </p>
    </li>
   </ul>
  </div>
  <p>
   Supplementary characters lie outside the BMP:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Their code point values are between
      <code class="literal">
       U+10000
      </code>
      and
      <code class="literal">
       U+10FFFF
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      Unicode support for supplementary characters requires
          character sets that have a range outside BMP characters and
          therefore take more space than BMP characters (up to 4 bytes
          per character).
     </p>
    </li>
   </ul>
  </div>
  <p>
   The UTF-8 (Unicode Transformation Format with 8-bit units) method
      for encoding Unicode data is implemented according to RFC 3629,
      which describes encoding sequences that take from one to four
      bytes. The idea of UTF-8 is that various Unicode characters are
      encoded using byte sequences of different lengths:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      Basic Latin letters, digits, and punctuation signs use one
          byte.
     </p>
    </li>
    <li class="listitem">
     <p>
      Most European and Middle East script letters fit into a 2-byte
          sequence: extended Latin letters (with tilde, macron, acute,
          grave and other accents), Cyrillic, Greek, Armenian, Hebrew,
          Arabic, Syriac, and others.
     </p>
    </li>
    <li class="listitem">
     <p>
      Korean, Chinese, and Japanese ideographs use 3-byte or 4-byte
          sequences.
     </p>
    </li>
   </ul>
  </div>
  <p>
   MySQL supports these Unicode character sets:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       utf8mb4
      </code>
      : A UTF-8 encoding of the Unicode
          character set using one to four bytes per character.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       utf8mb3
      </code>
      : A UTF-8 encoding of the Unicode
          character set using one to three bytes per character. This
          character set is deprecated andsubject to removal in a future
          release; use
      <code class="literal">
       utf8mb4
      </code>
      instead.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       utf8
      </code>
      : A deprecated alias for
      <code class="literal">
       utf8mb3
      </code>
      ; use
      <code class="literal">
       utf8mb4
      </code>
      instead.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       <code class="literal">
        utf8
       </code>
       is expected in a future version of
            MySQL to become an alias for
       <code class="literal">
        utf8mb4
       </code>
       .
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       ucs2
      </code>
      : The UCS-2 encoding of the Unicode
          character set using two bytes per character. Deprecated;
          expect support for this character set to be removed in a
          future release.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       utf16
      </code>
      : The UTF-16 encoding for the Unicode
          character set using two or four bytes per character. Like
      <code class="literal">
       ucs2
      </code>
      but with an extension for
          supplementary characters.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       utf16le
      </code>
      : The UTF-16LE encoding for the
          Unicode character set. Like
      <code class="literal">
       utf16
      </code>
      but
          little-endian rather than big-endian.
     </p>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       utf32
      </code>
      : The UTF-32 encoding for the Unicode
          character set using four bytes per character.
     </p>
    </li>
   </ul>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    The
    <code class="literal">
     utf8mb3
    </code>
    character set is deprecated and
        you should expect it to be removed in a future MySQL release.
        Please use
    <code class="literal">
     utf8mb4
    </code>
    instead.
    <code class="literal">
     utf8
    </code>
    is currently an alias for
    <code class="literal">
     utf8mb3
    </code>
    , but it is now deprecated as such,
        and
    <code class="literal">
     utf8
    </code>
    is expected subsequently to become a
        reference to
    <code class="literal">
     utf8mb4
    </code>
    . MySQL 8.4
        also displays
    <code class="literal">
     utf8mb3
    </code>
    in place of
    <code class="literal">
     utf8
    </code>
    in the columns of Information Schema
        tables, and in the output of SQL
    <code class="literal">
     SHOW
    </code>
    statements.
   </p>
   <p>
    In addition, you should be aware that collations using the
    <code class="literal">
     utf8_
    </code>
    prefix in older releases of MySQL have
        since been renamed using the prefix
    <code class="literal">
     utf8mb3_
    </code>
    ,
        instead.
   </p>
   <p>
    To avoid ambiguity about the meaning of
    <code class="literal">
     utf8
    </code>
    ,
        consider specifying
    <code class="literal">
     utf8mb4
    </code>
    explicitly for
        character set references.
   </p>
  </div>
  <p>
   <a class="xref" href="charset-unicode.html#charset-unicode-charset-characteristics" title="Table 12.2 Unicode Character Set General Characteristics">
    Table 12.2, “Unicode Character Set General Characteristics”
   </a>
   ,
      summarizes the general characteristics of Unicode character sets
      supported by MySQL.
  </p>
  <div class="table">
   <a name="charset-unicode-charset-characteristics">
   </a>
   <p class="title">
    <b>
     Table 12.2 Unicode Character Set General Characteristics
    </b>
   </p>
   <div class="table-contents">
    <table summary="General characteristics of Unicode character sets.">
     <colgroup>
      <col style="width: 20%"/>
      <col style="width: 40%"/>
      <col style="width: 40%"/>
     </colgroup>
     <thead>
      <tr>
       <th scope="col">
        Character Set
       </th>
       <th scope="col">
        Supported Characters
       </th>
       <th scope="col">
        Required Storage Per Character
       </th>
      </tr>
     </thead>
     <tbody>
      <tr>
       <th scope="row">
        <code class="literal">
         utf8mb3
        </code>
        ,
        <code class="literal">
         utf8
        </code>
        (deprecated)
       </th>
       <td>
        BMP only
       </td>
       <td>
        1, 2, or 3 bytes
       </td>
      </tr>
      <tr>
       <th scope="row">
        <code class="literal">
         ucs2
        </code>
       </th>
       <td>
        BMP only
       </td>
       <td>
        2 bytes
       </td>
      </tr>
      <tr>
       <th scope="row">
        <code class="literal">
         utf8mb4
        </code>
       </th>
       <td>
        BMP and supplementary
       </td>
       <td>
        1, 2, 3, or 4 bytes
       </td>
      </tr>
      <tr>
       <th scope="row">
        <code class="literal">
         utf16
        </code>
       </th>
       <td>
        BMP and supplementary
       </td>
       <td>
        2 or 4 bytes
       </td>
      </tr>
      <tr>
       <th scope="row">
        <code class="literal">
         utf16le
        </code>
       </th>
       <td>
        BMP and supplementary
       </td>
       <td>
        2 or 4 bytes
       </td>
      </tr>
      <tr>
       <th scope="row">
        <code class="literal">
         utf32
        </code>
       </th>
       <td>
        BMP and supplementary
       </td>
       <td>
        4 bytes
       </td>
      </tr>
     </tbody>
    </table>
   </div>
  </div>
  <br class="table-break"/>
  <p>
   Characters outside the BMP compare as
   <code class="literal">
    REPLACEMENT
      CHARACTER
   </code>
   and convert to
   <code class="literal">
    '?'
   </code>
   when
      converted to a Unicode character set that supports only BMP
      characters (
   <code class="literal">
    utf8mb3
   </code>
   or
   <code class="literal">
    ucs2
   </code>
   ).
  </p>
  <p>
   If you use character sets that support supplementary characters
      and thus are
   <span class="quote">
    “
    <span class="quote">
     wider
    </span>
    ”
   </span>
   than the BMP-only
   <code class="literal">
    utf8mb3
   </code>
   and
   <code class="literal">
    ucs2
   </code>
   character
      sets, there are potential incompatibility issues for your
      applications; see
   <a class="xref" href="charset-unicode-conversion.html" title="12.9.8 Converting Between 3-Byte and 4-Byte Unicode Character Sets">
    Section 12.9.8, “Converting Between 3-Byte and 4-Byte Unicode Character Sets”
   </a>
   .
      That section also describes how to convert tables from the
      (3-byte)
   <code class="literal">
    utf8mb3
   </code>
   to the (4-byte)
   <code class="literal">
    utf8mb4
   </code>
   , and what constraints may apply in
      doing so.
  </p>
  <p>
   A similar set of collations is available for most Unicode
      character sets. For example, each has a Danish collation, the
      names of which are
   <code class="literal">
    utf8mb4_danish_ci
   </code>
   ,
   <code class="literal">
    utf8mb3_danish_ci
   </code>
   (deprecated),
   <code class="literal">
    utf8_danish_ci
   </code>
   (deprecated),
   <code class="literal">
    ucs2_danish_ci
   </code>
   ,
   <code class="literal">
    utf16_danish_ci
   </code>
   , and
   <code class="literal">
    utf32_danish_ci
   </code>
   . The exception is
   <code class="literal">
    utf16le
   </code>
   , which has only two collations. For
      information about Unicode collations and their differentiating
      properties, including collation properties for supplementary
      characters, see
   <a class="xref" href="charset-unicode-sets.html" title="12.10.1 Unicode Character Sets">
    Section 12.10.1, “Unicode Character Sets”
   </a>
   .
  </p>
  <p>
   The MySQL implementation of UCS-2, UTF-16, and UTF-32 stores
      characters in big-endian byte order and does not use a byte order
      mark (BOM) at the beginning of values. Other database systems
      might use little-endian byte order or a BOM. In such cases,
      conversion of values needs to be performed when transferring data
      between those systems and MySQL. The implementation of UTF-16LE is
      little-endian.
  </p>
  <p>
   MySQL uses no BOM for UTF-8 values.
  </p>
  <p>
   Client applications that communicate with the server using Unicode
      should set the client character set accordingly (for example, by
      issuing a
   <code class="literal">
    SET NAMES 'utf8mb4'
   </code>
   statement). Some
      character sets cannot be used as the client character set.
      Attempting to use them with
   <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
    <code class="literal">
     SET
      NAMES
    </code>
   </a>
   or
   <a class="link" href="set-character-set.html" title="15.7.6.2 SET CHARACTER SET Statement">
    <code class="literal">
     SET CHARACTER
      SET
    </code>
   </a>
   produces an error. See
   <a class="xref" href="charset-connection.html#charset-connection-impermissible-client-charset" title="Impermissible Client Character Sets">
    Impermissible Client Character Sets
   </a>
   .
  </p>
  <p>
   The following sections provide additional detail on the Unicode
      character sets in MySQL.
  </p>
 </div>
 <br/>
</div>
