<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="charset-cp932">
      </a>
      12.10.7.1 The cp932 Character Set
     </h4>
    </div>
   </div>
  </div>
  <p>
   <span class="bold">
    <strong>
     Why is
     <code class="literal">
      cp932
     </code>
     needed?
    </strong>
   </span>
  </p>
  <p>
   In MySQL, the
   <code class="literal">
    sjis
   </code>
   character set
          corresponds to the
   <code class="literal">
    Shift_JIS
   </code>
   character set
          defined by IANA, which supports JIS X0201 and JIS X0208
          characters. (See
   <a class="ulink" href="http://www.iana.org/assignments/character-sets" target="_blank">
    http://www.iana.org/assignments/character-sets
   </a>
   .)
  </p>
  <p>
   However, the meaning of
   <span class="quote">
    “
    <span class="quote">
     SHIFT JIS
    </span>
    ”
   </span>
   as a
          descriptive term has become very vague and it often includes
          the extensions to
   <code class="literal">
    Shift_JIS
   </code>
   that are
          defined by various vendors.
  </p>
  <p>
   For example,
   <span class="quote">
    “
    <span class="quote">
     SHIFT JIS
    </span>
    ”
   </span>
   used in Japanese Windows
          environments is a Microsoft extension of
   <code class="literal">
    Shift_JIS
   </code>
   and its exact name is
   <code class="literal">
    Microsoft Windows Codepage : 932
   </code>
   or
   <code class="literal">
    cp932
   </code>
   . In addition to the characters
          supported by
   <code class="literal">
    Shift_JIS
   </code>
   ,
   <code class="literal">
    cp932
   </code>
   supports extension characters such as
          NEC special characters, NEC selected—IBM extended
          characters, and IBM selected characters.
  </p>
  <p>
   Many Japanese users have experienced problems using these
          extension characters. These problems stem from the following
          factors:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      MySQL automatically converts character sets.
     </p>
    </li>
    <li class="listitem">
     <p>
      Character sets are converted using Unicode
              (
      <code class="literal">
       ucs2
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      The
      <code class="literal">
       sjis
      </code>
      character set does not support
              the conversion of these extension characters.
     </p>
    </li>
    <li class="listitem">
     <p>
      There are several conversion rules from so-called
      <span class="quote">
       “
       <span class="quote">
        SHIFT JIS
       </span>
       ”
      </span>
      to Unicode, and some characters
              are converted to Unicode differently depending on the
              conversion rule. MySQL supports only one of these rules
              (described later).
     </p>
    </li>
   </ul>
  </div>
  <p>
   The MySQL
   <code class="literal">
    cp932
   </code>
   character set is designed
          to solve these problems.
  </p>
  <p>
   Because MySQL supports character set conversion, it is
          important to separate IANA
   <code class="literal">
    Shift_JIS
   </code>
   and
   <code class="literal">
    cp932
   </code>
   into two different character sets
          because they provide different conversion rules.
  </p>
  <p>
   <span class="bold">
    <strong>
     How does
     <code class="literal">
      cp932
     </code>
     differ
          from
     <code class="literal">
      sjis
     </code>
     ?
    </strong>
   </span>
  </p>
  <p>
   The
   <code class="literal">
    cp932
   </code>
   character set differs from
   <code class="literal">
    sjis
   </code>
   in the following ways:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <code class="literal">
       cp932
      </code>
      supports NEC special characters,
              NEC selected—IBM extended characters, and IBM
              selected characters.
     </p>
    </li>
    <li class="listitem">
     <p>
      Some
      <code class="literal">
       cp932
      </code>
      characters have two
              different code points, both of which convert to the same
              Unicode code point. When converting from Unicode back to
      <code class="literal">
       cp932
      </code>
      , one of the code points must be
              selected. For this
      <span class="quote">
       “
       <span class="quote">
        round trip conversion,
       </span>
       ”
      </span>
      the rule recommended by Microsoft is used. (See
      <a class="ulink" href="http://support.microsoft.com/kb/170559/EN-US/" target="_blank">
       http://support.microsoft.com/kb/170559/EN-US/
      </a>
      .)
     </p>
     <p>
      The conversion rule works like this:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         If the character is in both JIS X 0208 and NEC special
                  characters, use the code point of JIS X 0208.
        </p>
       </li>
       <li class="listitem">
        <p>
         If the character is in both NEC special characters and
                  IBM selected characters, use the code point of NEC
                  special characters.
        </p>
       </li>
       <li class="listitem">
        <p>
         If the character is in both IBM selected characters
                  and NEC selected—IBM extended characters, use
                  the code point of IBM extended characters.
        </p>
       </li>
      </ul>
     </div>
     <p>
      The table shown at
      <a class="ulink" href="https://msdn.microsoft.com/en-us/goglobal/cc305152.aspx" target="_blank">
       https://msdn.microsoft.com/en-us/goglobal/cc305152.aspx
      </a>
      provides information about the Unicode values of
      <code class="literal">
       cp932
      </code>
      characters. For
      <code class="literal">
       cp932
      </code>
      table entries with characters
              under which a four-digit number appears, the number
              represents the corresponding Unicode
              (
      <code class="literal">
       ucs2
      </code>
      ) encoding. For table entries with
              an underlined two-digit value appears, there is a range of
      <code class="literal">
       cp932
      </code>
      character values that begin with
              those two digits. Clicking such a table entry takes you to
              a page that displays the Unicode value for each of the
      <code class="literal">
       cp932
      </code>
      characters that begin with those
              digits.
     </p>
     <p>
      The following links are of special interest. They
              correspond to the encodings for the following sets of
              characters:
     </p>
     <div class="itemizedlist">
      <ul class="itemizedlist" style="list-style-type: circle; ">
       <li class="listitem">
        <p>
         NEC special characters (lead byte
         <code class="literal">
          0x87
         </code>
         ):
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting one-line language-html"><div class="docs-select-all right" id="sa81478078"><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-html">https://msdn.microsoft.com/en-us/goglobal/gg674964</code></pre>
        </div>
       </li>
       <li class="listitem">
        <p>
         NEC selected—IBM extended characters (lead byte
         <code class="literal">
          0xED
         </code>
         and
         <code class="literal">
          0xEE
         </code>
         ):
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting language-html"><div class="docs-select-all right" id="sa44540478"><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-html">https://msdn.microsoft.com/en-us/goglobal/gg671837
https://msdn.microsoft.com/en-us/goglobal/gg671838</code></pre>
        </div>
       </li>
       <li class="listitem">
        <p>
         IBM selected characters (lead byte
         <code class="literal">
          0xFA
         </code>
         ,
         <code class="literal">
          0xFB
         </code>
         ,
         <code class="literal">
          0xFC
         </code>
         ):
        </p>
        <div class="copytoclipboard-wrapper">
         <pre class="programlisting language-html"><div class="docs-select-all right" id="sa16524381"><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-html">https://msdn.microsoft.com/en-us/goglobal/gg671839
https://msdn.microsoft.com/en-us/goglobal/gg671840
https://msdn.microsoft.com/en-us/goglobal/gg671841</code></pre>
        </div>
       </li>
      </ul>
     </div>
    </li>
    <li class="listitem">
     <p>
      <code class="literal">
       cp932
      </code>
      supports conversion of
              user-defined characters in combination with
      <code class="literal">
       eucjpms
      </code>
      , and solves the problems with
      <code class="literal">
       sjis
      </code>
      /
      <code class="literal">
       ujis
      </code>
      conversion. For details, please refer to
      <a class="ulink" href="http://www.sljfaq.org/afaq/encodings.html" target="_blank">
       http://www.sljfaq.org/afaq/encodings.html
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   For some characters, conversion to and from
   <code class="literal">
    ucs2
   </code>
   is different for
   <code class="literal">
    sjis
   </code>
   and
   <code class="literal">
    cp932
   </code>
   . The
          following tables illustrate these differences.
  </p>
  <p>
   Conversion to
   <code class="literal">
    ucs2
   </code>
   :
  </p>
  <div class="informaltable">
   <table summary="sjis/cp932 values and the difference between sjis to ucs2 conversion and cp932 to ucs2 conversion.">
    <colgroup>
     <col style="width: 33%"/>
     <col style="width: 33%"/>
     <col style="width: 33%"/>
    </colgroup>
    <thead>
     <tr>
      <th scope="col">
       <code class="literal">
        sjis
       </code>
       /
       <code class="literal">
        cp932
       </code>
       Value
      </th>
      <th scope="col">
       <code class="literal">
        sjis
       </code>
       -&gt;
       <code class="literal">
        ucs2
       </code>
       Conversion
      </th>
      <th scope="col">
       <code class="literal">
        cp932
       </code>
       -&gt;
       <code class="literal">
        ucs2
       </code>
       Conversion
      </th>
     </tr>
    </thead>
    <tbody>
     <tr>
      <th scope="row">
       5C
      </th>
      <td>
       005C
      </td>
      <td>
       005C
      </td>
     </tr>
     <tr>
      <th scope="row">
       7E
      </th>
      <td>
       007E
      </td>
      <td>
       007E
      </td>
     </tr>
     <tr>
      <th scope="row">
       815C
      </th>
      <td>
       2015
      </td>
      <td>
       2015
      </td>
     </tr>
     <tr>
      <th scope="row">
       815F
      </th>
      <td>
       005C
      </td>
      <td>
       FF3C
      </td>
     </tr>
     <tr>
      <th scope="row">
       8160
      </th>
      <td>
       301C
      </td>
      <td>
       FF5E
      </td>
     </tr>
     <tr>
      <th scope="row">
       8161
      </th>
      <td>
       2016
      </td>
      <td>
       2225
      </td>
     </tr>
     <tr>
      <th scope="row">
       817C
      </th>
      <td>
       2212
      </td>
      <td>
       FF0D
      </td>
     </tr>
     <tr>
      <th scope="row">
       8191
      </th>
      <td>
       00A2
      </td>
      <td>
       FFE0
      </td>
     </tr>
     <tr>
      <th scope="row">
       8192
      </th>
      <td>
       00A3
      </td>
      <td>
       FFE1
      </td>
     </tr>
     <tr>
      <th scope="row">
       81CA
      </th>
      <td>
       00AC
      </td>
      <td>
       FFE2
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <div class="informaltable">
   <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 558px;">
    <thead>
     <tr>
      <th scope="col" style="width: 185.719px;">
       <code class="literal">
        sjis
       </code>
       /
       <code class="literal">
        cp932
       </code>
       Value
      </th>
      <th scope="col" style="width: 185.719px;">
       <code class="literal">
        sjis
       </code>
       -&gt;
       <code class="literal">
        ucs2
       </code>
       Conversion
      </th>
      <th scope="col" style="width: 185.75px;">
       <code class="literal">
        cp932
       </code>
       -&gt;
       <code class="literal">
        ucs2
       </code>
       Conversion
      </th>
     </tr>
    </thead>
   </table>
  </div>
  <p>
   Conversion from
   <code class="literal">
    ucs2
   </code>
   :
  </p>
  <div class="informaltable">
   <table summary="ucs2 values and the difference between ucs2 to sjis conversion and ucs2 to cp932 conversion.">
    <colgroup>
     <col style="width: 33%"/>
     <col style="width: 33%"/>
     <col style="width: 33%"/>
    </colgroup>
    <thead>
     <tr>
      <th scope="col">
       <code class="literal">
        ucs2
       </code>
       value
      </th>
      <th scope="col">
       <code class="literal">
        ucs2
       </code>
       -&gt;
       <code class="literal">
        sjis
       </code>
       Conversion
      </th>
      <th scope="col">
       <code class="literal">
        ucs2
       </code>
       -&gt;
       <code class="literal">
        cp932
       </code>
       Conversion
      </th>
     </tr>
    </thead>
    <tbody>
     <tr>
      <th scope="row">
       005C
      </th>
      <td>
       815F
      </td>
      <td>
       5C
      </td>
     </tr>
     <tr>
      <th scope="row">
       007E
      </th>
      <td>
       7E
      </td>
      <td>
       7E
      </td>
     </tr>
     <tr>
      <th scope="row">
       00A2
      </th>
      <td>
       8191
      </td>
      <td>
       3F
      </td>
     </tr>
     <tr>
      <th scope="row">
       00A3
      </th>
      <td>
       8192
      </td>
      <td>
       3F
      </td>
     </tr>
     <tr>
      <th scope="row">
       00AC
      </th>
      <td>
       81CA
      </td>
      <td>
       3F
      </td>
     </tr>
     <tr>
      <th scope="row">
       2015
      </th>
      <td>
       815C
      </td>
      <td>
       815C
      </td>
     </tr>
     <tr>
      <th scope="row">
       2016
      </th>
      <td>
       8161
      </td>
      <td>
       3F
      </td>
     </tr>
     <tr>
      <th scope="row">
       2212
      </th>
      <td>
       817C
      </td>
      <td>
       3F
      </td>
     </tr>
     <tr>
      <th scope="row">
       2225
      </th>
      <td>
       3F
      </td>
      <td>
       8161
      </td>
     </tr>
     <tr>
      <th scope="row">
       301C
      </th>
      <td>
       8160
      </td>
      <td>
       3F
      </td>
     </tr>
     <tr>
      <th scope="row">
       FF0D
      </th>
      <td>
       3F
      </td>
      <td>
       817C
      </td>
     </tr>
     <tr>
      <th scope="row">
       FF3C
      </th>
      <td>
       3F
      </td>
      <td>
       815F
      </td>
     </tr>
     <tr>
      <th scope="row">
       FF5E
      </th>
      <td>
       3F
      </td>
      <td>
       8160
      </td>
     </tr>
     <tr>
      <th scope="row">
       FFE0
      </th>
      <td>
       3F
      </td>
      <td>
       8191
      </td>
     </tr>
     <tr>
      <th scope="row">
       FFE1
      </th>
      <td>
       3F
      </td>
      <td>
       8192
      </td>
     </tr>
     <tr>
      <th scope="row">
       FFE2
      </th>
      <td>
       3F
      </td>
      <td>
       81CA
      </td>
     </tr>
    </tbody>
   </table>
  </div>
  <div class="informaltable">
   <table cellpadding="0" cellspacing="0" style="position: fixed; top: 0px; display: none; left: 401px; width: 558px;">
    <thead>
     <tr>
      <th scope="col" style="width: 185.719px;">
       <code class="literal">
        ucs2
       </code>
       value
      </th>
      <th scope="col" style="width: 185.719px;">
       <code class="literal">
        ucs2
       </code>
       -&gt;
       <code class="literal">
        sjis
       </code>
       Conversion
      </th>
      <th scope="col" style="width: 185.75px;">
       <code class="literal">
        ucs2
       </code>
       -&gt;
       <code class="literal">
        cp932
       </code>
       Conversion
      </th>
     </tr>
    </thead>
   </table>
  </div>
 </div>
 <br/>
</div>
