<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="create-database">
      </a>
      15.1.12 CREATE DATABASE Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045188339136">
  </a>
  <a class="indexterm" name="idm46045188337680">
  </a>
  <a class="indexterm" name="idm46045188336608">
  </a>
  <a class="indexterm" name="idm46045188335536">
  </a>
  <a class="indexterm" name="idm46045188334048">
  </a>
  <a class="indexterm" name="idm46045188332560">
  </a>
  <a class="indexterm" name="idm46045188331072">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa48288764"><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">CREATE</span> {<span class="token keyword">DATABASE</span> <span class="token operator">|</span> <span class="token keyword">SCHEMA</span>} <span class="token punctuation">[</span><span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span><span class="token punctuation">]</span> <em class="replaceable">db_name</em>
    <span class="token punctuation">[</span><em class="replaceable">create_option</em><span class="token punctuation">]</span> <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>

<em class="replaceable">create_option</em>: <span class="token punctuation">[</span><span class="token keyword">DEFAULT</span><span class="token punctuation">]</span> {
    <span class="token keyword">CHARACTER</span> <span class="token keyword">SET</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">charset_name</em>
  <span class="token operator">|</span> <span class="token keyword">COLLATE</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> <em class="replaceable">collation_name</em>
  <span class="token operator">|</span> <span class="token keyword">ENCRYPTION</span> <span class="token punctuation">[</span><span class="token operator">=</span><span class="token punctuation">]</span> {<span class="token string">'Y'</span> <span class="token operator">|</span> <span class="token string">'N'</span>}
}</code></pre>
  </div>
  <p>
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE DATABASE
    </code>
   </a>
   creates a database
      with the given name. To use this statement, you need the
   <a class="link" href="privileges-provided.html#priv_create">
    <code class="literal">
     CREATE
    </code>
   </a>
   privilege for the database.
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE
      SCHEMA
    </code>
   </a>
   is a synonym for
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE
      DATABASE
    </code>
   </a>
   .
  </p>
  <p>
   An error occurs if the database exists and you did not specify
   <code class="literal">
    IF NOT EXISTS
   </code>
   .
  </p>
  <p>
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE DATABASE
    </code>
   </a>
   is not permitted
      within a session that has an active
   <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements">
    <code class="literal">
     LOCK
      TABLES
    </code>
   </a>
   statement.
  </p>
  <p>
   Each
   <em class="replaceable">
    <code>
     create_option
    </code>
   </em>
   specifies a database
      characteristic. Database characteristics are stored in the data
      dictionary.
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The
      <code class="literal">
       CHARACTER SET
      </code>
      option specifies the
          default database character set. The
      <code class="literal">
       COLLATE
      </code>
      option specifies the default database collation. For
          information about character set and collation names, see
      <a class="xref" href="charset.html" title="Chapter 12 Character Sets, Collations, Unicode">
       Chapter 12,
       <i>
        Character Sets, Collations, Unicode
       </i>
      </a>
      .
     </p>
     <p>
      To see the available character sets and collations, use the
          the
      <a class="link" href="show-character-set.html" title="15.7.7.4 SHOW CHARACTER SET Statement">
       <code class="literal">
        SHOW CHARACTER SET
       </code>
      </a>
      and
      <a class="link" href="show-collation.html" title="15.7.7.5 SHOW COLLATION Statement">
       <code class="literal">
        SHOW COLLATION
       </code>
      </a>
      statements,
          respectively. See
      <a class="xref" href="show-character-set.html" title="15.7.7.4 SHOW CHARACTER SET Statement">
       Section 15.7.7.4, “SHOW CHARACTER SET Statement”
      </a>
      , and
      <a class="xref" href="show-collation.html" title="15.7.7.5 SHOW COLLATION Statement">
       Section 15.7.7.5, “SHOW COLLATION Statement”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      The
      <code class="literal">
       ENCRYPTION
      </code>
      option defines the default
          database encryption, which is inherited by tables created in
          the database. The permitted values are
      <code class="literal">
       'Y'
      </code>
      (encryption enabled) and
      <code class="literal">
       'N'
      </code>
      (encryption
          disabled). If the
      <code class="literal">
       ENCRYPTION
      </code>
      option is not
          specified, the value of the
      <a class="link" href="server-system-variables.html#sysvar_default_table_encryption">
       <code class="literal">
        default_table_encryption
       </code>
      </a>
      system variable defines the default database encryption. If
          the
      <a class="link" href="server-system-variables.html#sysvar_table_encryption_privilege_check">
       <code class="literal">
        table_encryption_privilege_check
       </code>
      </a>
      system variable is enabled, the
      <a class="link" href="privileges-provided.html#priv_table-encryption-admin">
       <code class="literal">
        TABLE_ENCRYPTION_ADMIN
       </code>
      </a>
      privilege is required to specify a default encryption setting
          that differs from the
      <a class="link" href="server-system-variables.html#sysvar_default_table_encryption">
       <code class="literal">
        default_table_encryption
       </code>
      </a>
      setting. For more information, see
      <a class="xref" href="innodb-data-encryption.html#innodb-schema-tablespace-encryption-default" title="Defining an Encryption Default for Schemas and General Tablespaces">
       Defining an Encryption Default for Schemas and General Tablespaces
      </a>
      .
     </p>
    </li>
   </ul>
  </div>
  <p>
   A database in MySQL is implemented as a directory containing files
      that correspond to tables in the database. Because there are no
      tables in a database when it is initially created, the
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE DATABASE
    </code>
   </a>
   statement creates
      only a directory under the MySQL data directory. Rules for
      permissible database names are given in
   <a class="xref" href="identifiers.html" title="11.2 Schema Object Names">
    Section 11.2, “Schema Object Names”
   </a>
   . If a database name contains special
      characters, the name for the database directory contains encoded
      versions of those characters as described in
   <a class="xref" href="identifier-mapping.html" title="11.2.4 Mapping of Identifiers to File Names">
    Section 11.2.4, “Mapping of Identifiers to File Names”
   </a>
   .
  </p>
  <p>
   Creating a database directory by manually creating a directory
      under the data directory (for example, with
   <span class="command">
    <strong>
     mkdir
    </strong>
   </span>
   ) is unsupported in MySQL
      8.4.
  </p>
  <p>
   When you create a database, let the server manage the directory
      and the files in it. Manipulating database directories and files
      directly can cause inconsistencies and unexpected results.
  </p>
  <a class="indexterm" name="idm46045188288032">
  </a>
  <a class="indexterm" name="idm46045188286528">
  </a>
  <p>
   MySQL has no limit on the number of databases. The underlying file
      system may have a limit on the number of directories.
  </p>
  <a class="indexterm" name="idm46045188284480">
  </a>
  <p>
   You can also use the
   <a class="link" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
    <span class="command">
     <strong>
      mysqladmin
     </strong>
    </span>
   </a>
   program to
      create databases. See
   <a class="xref" href="mysqladmin.html" title="6.5.2 mysqladmin — A MySQL Server Administration Program">
    Section 6.5.2, “mysqladmin — A MySQL Server Administration Program”
   </a>
   .
  </p>
 </div>
 <br/>
</div>
