<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="charset-server">
      </a>
      12.3.2 Server Character Set and Collation
     </h3>
    </div>
   </div>
  </div>
  <p>
   MySQL Server has a server character set and a server collation.
        By default, these are
   <code class="literal">
    utf8mb4
   </code>
   and
   <code class="literal">
    utf8mb4_0900_ai_ci
   </code>
   , but they can be set
        explicitly at server startup on the command line or in an option
        file and changed at runtime.
  </p>
  <p>
   Initially, the server character set and collation depend on the
        options that you use when you start
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   .
        You can use
   <a class="link" href="server-system-variables.html#sysvar_character_set_server">
    <code class="option">
     --character-set-server
    </code>
   </a>
   for the
        character set. Along with it, you can add
   <a class="link" href="server-system-variables.html#sysvar_collation_server">
    <code class="option">
     --collation-server
    </code>
   </a>
   for the
        collation. If you don't specify a character set, that is the
        same as saying
   <a class="link" href="server-system-variables.html#sysvar_character_set_server">
    <code class="option">
     --character-set-server=utf8mb4
    </code>
   </a>
   .
        If you specify only a character set (for example,
   <code class="literal">
    utf8mb4
   </code>
   ) but not a collation, that is the
        same as saying
   <a class="link" href="server-system-variables.html#sysvar_character_set_server">
    <code class="option">
     --character-set-server=utf8mb4
    </code>
   </a>
   <a class="link" href="server-system-variables.html#sysvar_collation_server">
    <code class="option">
     --collation-server=utf8mb4_0900_ai_ci
    </code>
   </a>
   because
   <code class="literal">
    utf8mb4_0900_ai_ci
   </code>
   is the default
        collation for
   <code class="literal">
    utf8mb4
   </code>
   . Therefore, the
        following three commands all have the same effect:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa34821747"><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">mysqld
mysqld <span class="token constant">--character-set-server</span><span class="token attr-value"><span class="token punctuation">=</span>utf8mb4</span>
mysqld <span class="token constant">--character-set-server</span><span class="token attr-value"><span class="token punctuation">=</span>utf8mb4</span> \
  <span class="token constant">--collation-server</span><span class="token attr-value"><span class="token punctuation">=</span>utf8mb4_0900_ai_ci</span></code></pre>
  </div>
  <p>
   One way to change the settings is by recompiling. To change the
        default server character set and collation when building from
        sources, use the
   <a class="link" href="source-configuration-options.html#option_cmake_default_charset">
    <code class="option">
     DEFAULT_CHARSET
    </code>
   </a>
   and
   <a class="link" href="source-configuration-options.html#option_cmake_default_collation">
    <code class="option">
     DEFAULT_COLLATION
    </code>
   </a>
   options for
   <span class="command">
    <strong>
     CMake
    </strong>
   </span>
   . For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa32126305"><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">cmake <span class="token punctuation">.</span> <span class="token constant">-DDEFAULT_CHARSET</span><span class="token attr-value"><span class="token punctuation">=</span>latin1</span></code></pre>
  </div>
  <p>
   Or:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa4612065"><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">cmake <span class="token punctuation">.</span> <span class="token constant">-DDEFAULT_CHARSET</span><span class="token attr-value"><span class="token punctuation">=</span>latin1</span> \
  <span class="token constant">-DDEFAULT_COLLATION</span><span class="token attr-value"><span class="token punctuation">=</span>latin1_german1_ci</span></code></pre>
  </div>
  <p>
   Both
   <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
    <span class="command">
     <strong>
      mysqld
     </strong>
    </span>
   </a>
   and
   <span class="command">
    <strong>
     CMake
    </strong>
   </span>
   verify that the character set/collation combination is valid. If
        not, each program displays an error message and terminates.
  </p>
  <p>
   The server character set and collation are used as default
        values if the database character set and collation are not
        specified in
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE DATABASE
    </code>
   </a>
   statements. They have no other purpose.
  </p>
  <p>
   The current server character set and collation can be determined
        from the values of 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. These variables can be changed at runtime.
  </p>
 </div>
 <br/>
</div>
