<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="charset-unicode-utf32">
      </a>
      12.9.7 The utf32 Character Set (UTF-32 Unicode Encoding)
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045216550592">
  </a>
  <p>
   The
   <code class="literal">
    utf32
   </code>
   character set is fixed length (like
   <code class="literal">
    ucs2
   </code>
   and unlike
   <code class="literal">
    utf16
   </code>
   ).
   <code class="literal">
    utf32
   </code>
   uses 32 bits for every character,
        unlike
   <code class="literal">
    ucs2
   </code>
   (which uses 16 bits for every
        character), and unlike
   <code class="literal">
    utf16
   </code>
   (which uses 16
        bits for some characters and 32 bits for others).
  </p>
  <p>
   <code class="literal">
    utf32
   </code>
   takes twice as much space as
   <code class="literal">
    ucs2
   </code>
   and more space than
   <code class="literal">
    utf16
   </code>
   , but
   <code class="literal">
    utf32
   </code>
   has the
        same advantage as
   <code class="literal">
    ucs2
   </code>
   that it is predictable
        for storage: The required number of bytes for
   <code class="literal">
    utf32
   </code>
   equals the number of characters times
        4. Also, unlike
   <code class="literal">
    utf16
   </code>
   , there are no tricks
        for encoding in
   <code class="literal">
    utf32
   </code>
   , so the stored value
        equals the code value.
  </p>
  <p>
   To demonstrate how the latter advantage is useful, here is an
        example that shows how to determine a
   <code class="literal">
    utf8mb4
   </code>
   value given the
   <code class="literal">
    utf32
   </code>
   code value:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29355604"><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-sql"><span class="token comment" spellcheck="true">/* Assume code value = 100cc LINEAR B WHEELED CHARIOT */</span>
<span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> tmp <span class="token punctuation">(</span>utf32_col <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf32<span class="token punctuation">,</span>
                  utf8mb4_col <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">)</span> <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> utf8mb4<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> tmp <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">0x000100cc</span><span class="token punctuation">,</span><span class="token boolean">NULL</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">UPDATE</span> tmp <span class="token keyword">SET</span> utf8mb4_col <span class="token operator">=</span> utf32_col<span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token function">HEX</span><span class="token punctuation">(</span>utf32_col<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token function">HEX</span><span class="token punctuation">(</span>utf8mb4_col<span class="token punctuation">)</span> <span class="token keyword">FROM</span> tmp<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   MySQL is very forgiving about additions of unassigned Unicode
        characters or private-use-area characters. There is in fact only
        one validity check for
   <code class="literal">
    utf32
   </code>
   : No code value
        may be greater than
   <code class="literal">
    0x10ffff
   </code>
   . For example,
        this is illegal:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa61509984"><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-sql"><span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> t <span class="token punctuation">(</span>utf32_column<span class="token punctuation">)</span> <span class="token keyword">VALUES</span> <span class="token punctuation">(</span><span class="token number">0x110000</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment" spellcheck="true">/* illegal */</span></code></pre>
  </div>
 </div>
 <br/>
</div>
