<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="charset-connection">
      </a>
      12.4 Connection Character Sets and Collations
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045217500720">
  </a>
  <a class="indexterm" name="idm46045217499296">
  </a>
  <p>
   A
   <span class="quote">
    “
    <span class="quote">
     connection
    </span>
    ”
   </span>
   is what a client program makes when it
      connects to the server, to begin a session within which it
      interacts with the server. The client sends SQL statements, such
      as queries, over the session connection. The server sends
      responses, such as result sets or error messages, over the
      connection back to the client.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="charset-connection.html#charset-connection-system-variables" title="Connection Character Set and Collation System Variables">
       Connection Character Set and Collation System Variables
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="charset-connection.html#charset-connection-impermissible-client-charset" title="Impermissible Client Character Sets">
       Impermissible Client Character Sets
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="charset-connection.html#charset-connection-client-configuration" title="Client Program Connection Character Set Configuration">
       Client Program Connection Character Set Configuration
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="charset-connection.html#charset-connection-sql-statements" title="SQL Statements for Connection Character Set Configuration">
       SQL Statements for Connection Character Set Configuration
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="charset-connection.html#charset-connection-error-handling" title="Connection Character Set Error Handling">
       Connection Character Set Error Handling
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-connection-system-variables">
       </a>
       Connection Character Set and Collation System Variables
      </h3>
     </div>
    </div>
   </div>
   <p>
    Several character set and collation system variables relate to a
        client's interaction with the server. Some of these have been
        mentioned in earlier sections:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The
       <a class="link" href="server-system-variables.html#sysvar_character_set_server">
        <code class="literal">
         character_set_server
        </code>
       </a>
       and
       <a class="link" href="server-system-variables.html#sysvar_collation_server">
        <code class="literal">
         collation_server
        </code>
       </a>
       system
            variables indicate the server character set and collation.
            See
       <a class="xref" href="charset-server.html" title="12.3.2 Server Character Set and Collation">
        Section 12.3.2, “Server Character Set and Collation”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="server-system-variables.html#sysvar_character_set_database">
        <code class="literal">
         character_set_database
        </code>
       </a>
       and
       <a class="link" href="server-system-variables.html#sysvar_collation_database">
        <code class="literal">
         collation_database
        </code>
       </a>
       system variables indicate the character set and collation of
            the default database. See
       <a class="xref" href="charset-database.html" title="12.3.3 Database Character Set and Collation">
        Section 12.3.3, “Database Character Set and Collation”
       </a>
       .
      </p>
     </li>
    </ul>
   </div>
   <p>
    Additional character set and collation system variables are
        involved in handling traffic for the connection between a client
        and the server. Every client has session-specific
        connection-related character set and collation system variables.
        These session system variable values are initialized at connect
        time, but can be changed within the session.
   </p>
   <p>
    Several questions about character set and collation handling for
        client connections can be answered in terms of system variables:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       What character set are statements in when they leave the
            client?
      </p>
      <p>
       The server takes the
       <a class="link" href="server-system-variables.html#sysvar_character_set_client">
        <code class="literal">
         character_set_client
        </code>
       </a>
       system
            variable to be the character set in which statements are
            sent by the client.
      </p>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
       <div class="admon-title">
        Note
       </div>
       <p>
        Some character sets cannot be used as the client character
              set. See
        <a class="xref" href="charset-connection.html#charset-connection-impermissible-client-charset" title="Impermissible Client Character Sets">
         Impermissible Client Character Sets
        </a>
        .
       </p>
      </div>
     </li>
     <li class="listitem">
      <p>
       What character set should the server translate statements to
            after receiving them?
      </p>
      <p>
       To determine this, the server uses the
       <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
        <code class="literal">
         character_set_connection
        </code>
       </a>
       and
       <a class="link" href="server-system-variables.html#sysvar_collation_connection">
        <code class="literal">
         collation_connection
        </code>
       </a>
       system variables:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: circle; ">
        <li class="listitem">
         <p>
          The server converts statements sent by the client from
          <a class="link" href="server-system-variables.html#sysvar_character_set_client">
           <code class="literal">
            character_set_client
           </code>
          </a>
          to
          <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
           <code class="literal">
            character_set_connection
           </code>
          </a>
          .
                Exception: For string literals that have an introducer
                such as
          <code class="literal">
           _utf8mb4
          </code>
          or
          <code class="literal">
           _latin2
          </code>
          , the introducer determines
                the character set. See
          <a class="xref" href="charset-introducer.html" title="12.3.8 Character Set Introducers">
           Section 12.3.8, “Character Set Introducers”
          </a>
          .
         </p>
        </li>
        <li class="listitem">
         <p>
          <a class="link" href="server-system-variables.html#sysvar_collation_connection">
           <code class="literal">
            collation_connection
           </code>
          </a>
          is
                important for comparisons of literal strings. For
                comparisons of strings with column values,
          <a class="link" href="server-system-variables.html#sysvar_collation_connection">
           <code class="literal">
            collation_connection
           </code>
          </a>
          does not matter because columns have their own
                collation, which has a higher collation precedence (see
          <a class="xref" href="charset-collation-coercibility.html" title="12.8.4 Collation Coercibility in Expressions">
           Section 12.8.4, “Collation Coercibility in Expressions”
          </a>
          ).
         </p>
        </li>
       </ul>
      </div>
     </li>
     <li class="listitem">
      <p>
       What character set should the server translate query results
            to before shipping them back to the client?
      </p>
      <p>
       The
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       system variable indicates the character set in which the
            server returns query results to the client. This includes
            result data such as column values, result metadata such as
            column names, and error messages.
      </p>
      <p>
       To tell the server to perform no conversion of result sets
            or error messages, set
       <a class="link" href="server-system-variables.html#sysvar_character_set_results">
        <code class="literal">
         character_set_results
        </code>
       </a>
       to
       <code class="literal">
        NULL
       </code>
       or
       <code class="literal">
        binary
       </code>
       :
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa23548271"><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">SET</span> character_set_results <span class="token operator">=</span> <span class="token boolean">NULL</span><span class="token punctuation">;</span>
<span class="token keyword">SET</span> character_set_results <span class="token operator">=</span> <span class="token datatype">binary</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       For more information about character sets and error
            messages, see
       <a class="xref" href="charset-errors.html" title="12.6 Error Message Character Set">
        Section 12.6, “Error Message Character Set”
       </a>
       .
      </p>
     </li>
    </ul>
   </div>
   <p>
    To see the values of the character set and collation system
        variables that apply to the current session, use this statement:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa29655615"><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">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> performance_schema<span class="token punctuation">.</span>session_variables
<span class="token keyword">WHERE</span> VARIABLE_NAME <span class="token keyword">IN</span> <span class="token punctuation">(</span>
  <span class="token string">'character_set_client'</span><span class="token punctuation">,</span> <span class="token string">'character_set_connection'</span><span class="token punctuation">,</span>
  <span class="token string">'character_set_results'</span><span class="token punctuation">,</span> <span class="token string">'collation_connection'</span>
<span class="token punctuation">)</span> <span class="token keyword">ORDER</span> <span class="token keyword">BY</span> VARIABLE_NAME<span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    The following simpler statements also display the connection
        variables, but include other related variables as well. They can
        be useful to see
    <span class="emphasis">
     <em>
      all
     </em>
    </span>
    character set and
        collation system variables:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa72365866"><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">SHOW</span> <span class="token keyword">SESSION</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'character\_set\_%'</span><span class="token punctuation">;</span>
<span class="token keyword">SHOW</span> <span class="token keyword">SESSION</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'collation\_%'</span><span class="token punctuation">;</span></code></pre>
   </div>
   <p>
    Clients can fine-tune the settings for these variables, or
        depend on the defaults (in which case, you can skip the rest of
        this section). If you do not use the defaults, you must change
        the character settings
    <span class="emphasis">
     <em>
      for each connection to the
        server
     </em>
    </span>
    .
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-connection-impermissible-client-charset">
       </a>
       Impermissible Client Character Sets
      </h3>
     </div>
    </div>
   </div>
   <a class="indexterm" name="idm46045217445920">
   </a>
   <a class="indexterm" name="idm46045217444432">
   </a>
   <a class="indexterm" name="idm46045217442944">
   </a>
   <a class="indexterm" name="idm46045217441456">
   </a>
   <p>
    The
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    system
        variable cannot be set to certain character sets:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-simple"><div class="docs-select-all right" id="sa53895539"><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-simple">ucs2
utf16
utf16le
utf32</code></pre>
   </div>
   <p>
    Attempting to use any of those character sets as the client
        character set produces an error:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa59988269"><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 prompt">mysql&gt;</span> <span class="token keyword">SET</span> character_set_client <span class="token operator">=</span> <span class="token string">'ucs2'</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1231 (42000)<span class="token punctuation">:</span> Variable 'character_set_client'
can't be set to the value of 'ucs2'</span></code></pre>
   </div>
   <p>
    The same error occurs if any of those character sets are used in
        the following contexts, all of which result in an attempt to set
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    to the
        named character set:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       The
       <a class="link" href="mysql-command-options.html#option_mysql_default-character-set">
        <code class="option">
         --default-character-set=
         <em class="replaceable">
          <code>
           charset_name
          </code>
         </em>
        </code>
       </a>
       command option used by MySQL client programs such as
       <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
        <span class="command">
         <strong>
          mysql
         </strong>
        </span>
       </a>
       and
       <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
        <span class="command">
         <strong>
          mysqladmin
         </strong>
        </span>
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
        <code class="literal">
         SET NAMES
            '
         <em class="replaceable">
          <code>
           charset_name
          </code>
         </em>
         '
        </code>
       </a>
       statement.
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="set-character-set.html" title="15.7.6.2 SET CHARACTER SET Statement">
        <code class="literal">
         SET
            CHARACTER SET
            '
         <em class="replaceable">
          <code>
           charset_name
          </code>
         </em>
         '
        </code>
       </a>
       statement.
      </p>
     </li>
    </ul>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-connection-client-configuration">
       </a>
       Client Program Connection Character Set Configuration
      </h3>
     </div>
    </div>
   </div>
   <p>
    When a client connects to the server, it indicates which
        character set it wants to use for communication with the server.
        (Actually, the client indicates the default collation for that
        character set, from which the server can determine the character
        set.) The server uses this information to set the
    <a class="link" href="server-system-variables.html#sysvar_character_set_client">
     <code class="literal">
      character_set_client
     </code>
    </a>
    ,
    <a class="link" href="server-system-variables.html#sysvar_character_set_results">
     <code class="literal">
      character_set_results
     </code>
    </a>
    ,
    <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
     <code class="literal">
      character_set_connection
     </code>
    </a>
    system
        variables to the character set, and
    <a class="link" href="server-system-variables.html#sysvar_collation_connection">
     <code class="literal">
      collation_connection
     </code>
    </a>
    to the
        character set default collation. In effect, the server performs
        the equivalent of a
    <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
     <code class="literal">
      SET NAMES
     </code>
    </a>
    operation.
   </p>
   <p>
    If the server does not support the requested character set or
        collation, it falls back to using the server character set and
        collation to configure the connection. For additional detail
        about this fallback behavior, see
    <a class="xref" href="charset-connection.html#charset-connection-error-handling" title="Connection Character Set Error Handling">
     Connection Character Set Error Handling
    </a>
    .
   </p>
   <p>
    The
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    ,
    <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
     <span class="command">
      <strong>
       mysqladmin
      </strong>
     </span>
    </a>
    ,
    <a class="link" href="mysqlcheck.html" title="6.5.3 mysqlcheck — A Table Maintenance Program">
     <span class="command">
      <strong>
       mysqlcheck
      </strong>
     </span>
    </a>
    ,
    <a class="link" href="mysqlimport.html" title="6.5.5 mysqlimport — A Data Import Program">
     <span class="command">
      <strong>
       mysqlimport
      </strong>
     </span>
    </a>
    ,
        and
    <a class="link" href="mysqlshow.html" title="6.5.6 mysqlshow — Display Database, Table, and Column Information">
     <span class="command">
      <strong>
       mysqlshow
      </strong>
     </span>
    </a>
    client programs determine the
        default character set to use as follows:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       In the absence of other information, each client uses the
            compiled-in default character set, usually
       <code class="literal">
        utf8mb4
       </code>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       Each client can autodetect which character set to use based
            on the operating system setting, such as the value of the
       <code class="literal">
        LANG
       </code>
       or
       <code class="literal">
        LC_ALL
       </code>
       locale
            environment variable on Unix systems or the code page
            setting on Windows systems. For systems on which the locale
            is available from the OS, the client uses it to set the
            default character set rather than using the compiled-in
            default. For example, setting
       <code class="literal">
        LANG
       </code>
       to
       <code class="literal">
        ru_RU.KOI8-R
       </code>
       causes the
       <code class="literal">
        koi8r
       </code>
       character set to be used. Thus,
            users can configure the locale in their environment for use
            by MySQL clients.
      </p>
      <p>
       The OS character set is mapped to the closest MySQL
            character set if there is no exact match. If the client does
            not support the matching character set, it uses the
            compiled-in default. For example,
       <code class="literal">
        utf8
       </code>
       and
       <code class="literal">
        utf-8
       </code>
       map to
       <code class="literal">
        utf8mb4
       </code>
       , and
       <code class="literal">
        ucs2
       </code>
       is
            not supported as a connection character set, so it maps to
            the compiled-in default.
      </p>
      <p>
       C applications can use character set autodetection based on
            the OS setting by invoking
       <a class="ulink" href="/doc/c-api/8.4/en/mysql-options.html" target="_top">
        <code class="literal">
         mysql_options()
        </code>
       </a>
       as follows
            before connecting to the server:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-c"><div class="docs-select-all right" id="sa94643175"><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-c"><span class="token function">mysql_options</span><span class="token punctuation">(</span>mysql<span class="token punctuation">,</span>
              MYSQL_SET_CHARSET_NAME<span class="token punctuation">,</span>
              MYSQL_AUTODETECT_CHARSET_NAME<span class="token punctuation">)</span><span class="token punctuation">;</span></code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Each client supports a
       <a class="link" href="mysql-command-options.html#option_mysql_default-character-set">
        <code class="option">
         --default-character-set
        </code>
       </a>
       option, which enables users to specify the character set
            explicitly to override whatever default the client otherwise
            determines.
      </p>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
       <div class="admon-title">
        Note
       </div>
       <p>
        Some character sets cannot be used as the client character
              set. Attempting to use them with
        <a class="link" href="mysql-command-options.html#option_mysql_default-character-set">
         <code class="option">
          --default-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>
      </div>
     </li>
    </ul>
   </div>
   <p>
    With the
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    client, to use a character set
        different from the default, you could explicitly execute a
    <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
     <code class="literal">
      SET NAMES
     </code>
    </a>
    statement every time
        you connect to the server (see
    <a class="xref" href="charset-connection.html#charset-connection-client-configuration" title="Client Program Connection Character Set Configuration">
     Client Program Connection Character Set Configuration
    </a>
    ). To
        accomplish the same result more easily, specify the character
        set in your option file. For example, the following option file
        setting changes the three connection-related character set
        system variables set to
    <code class="literal">
     koi8r
    </code>
    each time you
        invoke
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    :
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa58596468"><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-ini"><span class="token selector">[mysql]</span>
<span class="token constant">default-character-set</span><span class="token attr-value"><span class="token punctuation">=</span>koi8r</span></code></pre>
   </div>
   <p>
    If you are using the
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    client with
        auto-reconnect enabled (which is not recommended), it is
        preferable to use the
    <code class="literal">
     charset
    </code>
    command rather
        than
    <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
     <code class="literal">
      SET NAMES
     </code>
    </a>
    . For example:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa65618298"><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 prompt">mysql&gt;</span> <span class="token keyword">charset</span> koi8r
<span class="token keyword">Charset</span> <span class="token keyword">changed</span></code></pre>
   </div>
   <p>
    The
    <code class="literal">
     charset
    </code>
    command issues a
    <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
     <code class="literal">
      SET NAMES
     </code>
    </a>
    statement, and also
        changes the default character set that
    <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
     <span class="command">
      <strong>
       mysql
      </strong>
     </span>
    </a>
    uses when it reconnects after the connection has dropped.
   </p>
   <p>
    When configuration client programs, you must also consider the
        environment within which they execute. See
    <a class="xref" href="charset-applications.html" title="12.5 Configuring Application Character Set and Collation">
     Section 12.5, “Configuring Application Character Set and Collation”
    </a>
    .
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-connection-sql-statements">
       </a>
       SQL Statements for Connection Character Set Configuration
      </h3>
     </div>
    </div>
   </div>
   <p>
    After a connection has been established, clients can change the
        character set and collation system variables for the current
        session. These variables can be changed individually using
    <a class="link" href="set-statement.html" title="15.7.6 SET Statements">
     <code class="literal">
      SET
     </code>
    </a>
    statements, but two more convenient statements affect the
        connection-related character set system variables as a group:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <code class="literal">
        SET NAMES '
        <em class="replaceable">
         <code>
          charset_name
         </code>
        </em>
        '
            [COLLATE
            '
        <em class="replaceable">
         <code>
          collation_name
         </code>
        </em>
        ']
       </code>
      </p>
      <p>
       <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
        <code class="literal">
         SET NAMES
        </code>
       </a>
       indicates what
            character set the client uses to send SQL statements to the
            server. Thus,
       <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
        <code class="literal">
         SET
            NAMES 'cp1251'
        </code>
       </a>
       tells the server,
       <span class="quote">
        “
        <span class="quote">
         future
            incoming messages from this client are in character set
         <code class="literal">
          cp1251
         </code>
         .
        </span>
        ”
       </span>
       It also specifies the
            character set that the server should use for sending results
            back to the client. (For example, it indicates what
            character set to use for column values if you use a
       <a class="link" href="select.html" title="15.2.13 SELECT Statement">
        <code class="literal">
         SELECT
        </code>
       </a>
       statement that
            produces a result set.)
      </p>
      <p>
       A
       <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
        <code class="literal">
         SET NAMES
            '
         <em class="replaceable">
          <code>
           charset_name
          </code>
         </em>
         '
        </code>
       </a>
       statement is equivalent to these three statements:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa36956650"><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">SET</span> character_set_client <span class="token operator">=</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span>
<span class="token keyword">SET</span> character_set_results <span class="token operator">=</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span>
<span class="token keyword">SET</span> character_set_connection <span class="token operator">=</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       Setting
       <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
        <code class="literal">
         character_set_connection
        </code>
       </a>
       to
       <em class="replaceable">
        <code>
         charset_name
        </code>
       </em>
       also implicitly sets
       <a class="link" href="server-system-variables.html#sysvar_collation_connection">
        <code class="literal">
         collation_connection
        </code>
       </a>
       to the
            default collation for
       <em class="replaceable">
        <code>
         charset_name
        </code>
       </em>
       . It is unnecessary
            to set that collation explicitly. To specify a particular
            collation to use for
       <a class="link" href="server-system-variables.html#sysvar_collation_connection">
        <code class="literal">
         collation_connection
        </code>
       </a>
       , add a
       <code class="literal">
        COLLATE
       </code>
       clause:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa67500059"><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">SET</span> <span class="token keyword">NAMES</span> <span class="token string">'<em class="replaceable">charset_name</em>'</span> <span class="token keyword">COLLATE</span> <span class="token string">'<em class="replaceable">collation_name</em>'</span></code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       <code class="literal">
        SET CHARACTER SET
            '
        <em class="replaceable">
         <code>
          charset_name
         </code>
        </em>
       </code>
       '
      </p>
      <p>
       <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>
       is similar
            to
       <a class="link" href="set-names.html" title="15.7.6.3 SET NAMES Statement">
        <code class="literal">
         SET NAMES
        </code>
       </a>
       but sets
       <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
        <code class="literal">
         character_set_connection
        </code>
       </a>
       and
       <a class="link" href="server-system-variables.html#sysvar_collation_connection">
        <code class="literal">
         collation_connection
        </code>
       </a>
       to
       <a class="link" href="server-system-variables.html#sysvar_character_set_database">
        <code class="literal">
         character_set_database
        </code>
       </a>
       and
       <a class="link" href="server-system-variables.html#sysvar_collation_database">
        <code class="literal">
         collation_database
        </code>
       </a>
       (which,
            as mentioned previously, indicate the character set and
            collation of the default database).
      </p>
      <p>
       A
       <a class="link" href="set-character-set.html" title="15.7.6.2 SET CHARACTER SET Statement">
        <code class="literal">
         SET
            CHARACTER SET
         <em class="replaceable">
          <code>
           charset_name
          </code>
         </em>
        </code>
       </a>
       statement
            is equivalent to these three statements:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa7373368"><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">SET</span> character_set_client <span class="token operator">=</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span>
<span class="token keyword">SET</span> character_set_results <span class="token operator">=</span> <em class="replaceable">charset_name</em><span class="token punctuation">;</span>
<span class="token keyword">SET</span> collation_connection <span class="token operator">=</span> <span class="token variable">@@collation_database</span><span class="token punctuation">;</span></code></pre>
      </div>
      <p>
       Setting
       <a class="link" href="server-system-variables.html#sysvar_collation_connection">
        <code class="literal">
         collation_connection
        </code>
       </a>
       also
            implicitly sets
       <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
        <code class="literal">
         character_set_connection
        </code>
       </a>
       to
            the character set associated with the collation (equivalent
            to executing
       <code class="literal">
        SET character_set_connection =
            @@character_set_database
       </code>
       ). It is unnecessary to
            set
       <a class="link" href="server-system-variables.html#sysvar_character_set_connection">
        <code class="literal">
         character_set_connection
        </code>
       </a>
       explicitly.
      </p>
     </li>
    </ul>
   </div>
   <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Note
    </div>
    <p>
     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>
   </div>
   <p>
    Example: Suppose that
    <code class="literal">
     column1
    </code>
    is defined as
    <code class="literal">
     CHAR(5) CHARACTER SET latin2
    </code>
    . If you do not
        say
    <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>
    , then for
    <code class="literal">
     SELECT column1 FROM t
    </code>
    , the server sends back
        all the values for
    <code class="literal">
     column1
    </code>
    using the
        character set that the client specified when it connected. On
        the other hand, if you say
    <code class="literal">
     SET NAMES 'latin1'
    </code>
    or
    <code class="literal">
     SET CHARACTER SET 'latin1'
    </code>
    before issuing
        the
    <a class="link" href="select.html" title="15.2.13 SELECT Statement">
     <code class="literal">
      SELECT
     </code>
    </a>
    statement, the server
        converts the
    <code class="literal">
     latin2
    </code>
    values to
    <code class="literal">
     latin1
    </code>
    just before sending results back.
        Conversion may be lossy for characters that are not in both
        character sets.
   </p>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h3 class="title">
       <a name="charset-connection-error-handling">
       </a>
       Connection Character Set Error Handling
      </h3>
     </div>
    </div>
   </div>
   <p>
    Attempts to use an inappropriate connection character set or
        collation can produce an error, or cause the server to fall back
        to its default character set and collation for a given
        connection. This section describes problems that can occur when
        configuring the connection character set. These problems can
        occur when establishing a connection or when changing the
        character set within an established connection.
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       <a class="xref" href="charset-connection.html#charset-connection-error-handling-connect-time" title="Connect-Time Error Handling">
        Connect-Time Error Handling
       </a>
      </p>
     </li>
     <li class="listitem">
      <p>
       <a class="xref" href="charset-connection.html#charset-connection-error-handling-runtime" title="Runtime Error Handling">
        Runtime Error Handling
       </a>
      </p>
     </li>
    </ul>
   </div>
   <h4>
    <a name="charset-connection-error-handling-connect-time">
    </a>
    Connect-Time Error Handling
   </h4>
   <p>
    Some character sets cannot be used as the client character set;
        see
    <a class="xref" href="charset-connection.html#charset-connection-impermissible-client-charset" title="Impermissible Client Character Sets">
     Impermissible Client Character Sets
    </a>
    .
        If you specify a character set that is valid but not permitted
        as a client character set, the server returns an error:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa20658202"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> <span class="token constant">--default-character-set</span><span class="token attr-value"><span class="token punctuation">=</span>ucs2</span>
<span class="token output">ERROR 1231 (42000)<span class="token punctuation">:</span> Variable 'character_set_client' can't be set to
the value of 'ucs2'</span></code></pre>
   </div>
   <p>
    If you specify a character set that the client does not
        recognize, it produces an error:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa76698779"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> <span class="token constant">--default-character-set</span><span class="token attr-value"><span class="token punctuation">=</span>bogus</span>
mysql<span class="token punctuation">:</span> Character set <span class="token atrule">'bogus'</span> is not a compiled character set and is
not specified in the <span class="token atrule">'/usr/local/mysql/share/charsets/Index.xml'</span> file
<span class="token output">ERROR 2019 (HY000)<span class="token punctuation">:</span> Can't initialize character set bogus
(path<span class="token punctuation">:</span> /usr/local/mysql/share/charsets/)</span></code></pre>
   </div>
   <p>
    If you specify a character set that the client recognizes but
        the server does not, the server falls back to its default
        character set and collation. Suppose that the server is
        configured to use
    <code class="literal">
     latin1
    </code>
    and
    <code class="literal">
     latin1_swedish_ci
    </code>
    as its defaults, and that
        it does not recognize
    <code class="literal">
     gb18030
    </code>
    as a valid
        character set. A client that specifies
    <a class="link" href="mysql-command-options.html#option_mysql_default-character-set">
     <code class="option">
      --default-character-set=gb18030
     </code>
    </a>
    is
        able to connect to the server, but the resulting character set
        is not what the client wants:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33799621"><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 prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">SESSION</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'character\_set\_%'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Variable_name            <span class="token punctuation">|</span> Value  <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_client     <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> character_set_connection <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token output"><span class="token punctuation">|</span> character_set_results    <span class="token punctuation">|</span> latin1 <span class="token punctuation">|</span></span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SHOW</span> <span class="token keyword">SESSION</span> <span class="token keyword">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'collation_connection'</span><span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> Variable_name        <span class="token punctuation">|</span> Value             <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> collation_connection <span class="token punctuation">|</span> latin1_swedish_ci <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span></code></pre>
   </div>
   <p>
    You can see that the connection system variables have been set
        to reflect a character set and collation of
    <code class="literal">
     latin1
    </code>
    and
    <code class="literal">
     latin1_swedish_ci
    </code>
    . This occurs because the
        server cannot satisfy the client character set request and falls
        back to its defaults.
   </p>
   <p>
    In this case, the client cannot use the character set that it
        wants because the server does not support it. The client must
        either be willing to use a different character set, or connect
        to a different server that supports the desired character set.
   </p>
   <p>
    The same problem occurs when the client tells the server to use
        a character set that the server recognizes, but the default
        collation for that character set on the client side is not known
        on the server side.
   </p>
   <h4>
    <a name="charset-connection-error-handling-runtime">
    </a>
    Runtime Error Handling
   </h4>
   <p>
    Within an established connection, the client can request a
        change of connection character set and collation 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>
    .
   </p>
   <p>
    Some character sets cannot be used as the client character set;
        see
    <a class="xref" href="charset-connection.html#charset-connection-impermissible-client-charset" title="Impermissible Client Character Sets">
     Impermissible Client Character Sets
    </a>
    .
        If you specify a character set that is valid but not permitted
        as a client character set, the server returns an error:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa47963678"><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 prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token keyword">NAMES</span> <span class="token string">'ucs2'</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1231 (42000)<span class="token punctuation">:</span> Variable 'character_set_client' can't be set to
the value of 'ucs2'</span></code></pre>
   </div>
   <p>
    If the server does not recognize the character set (or the
        collation), it produces an error:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa68250687"><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 prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token keyword">NAMES</span> <span class="token string">'bogus'</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1115 (42000)<span class="token punctuation">:</span> Unknown character set<span class="token punctuation">:</span> 'bogus'
</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">SET</span> <span class="token keyword">NAMES</span> <span class="token string">'utf8mb4'</span> <span class="token keyword">COLLATE</span> <span class="token string">'bogus'</span><span class="token punctuation">;</span>
<span class="token output">ERROR 1273 (HY000)<span class="token punctuation">:</span> Unknown collation<span class="token punctuation">:</span> 'bogus'</span></code></pre>
   </div>
   <div class="tip" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Tip
    </div>
    <p>
     A client that wants to verify whether its requested character
          set was honored by the server can execute the following
          statement after connecting and checking that the result is the
          expected character set:
    </p>
    <div class="copytoclipboard-wrapper">
     <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa96308007"><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">SELECT</span> <span class="token variable">@@character_set_client</span><span class="token punctuation">;</span></code></pre>
    </div>
   </div>
  </div>
 </div>
 <br/>
</div>
