<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="data-directory-initialization">
      </a>
      2.9.1 Initializing the Data Directory
     </h3>
    </div>
   </div>
  </div>
  <p>
   After MySQL is installed, the data directory must be initialized,
      including the tables in the
   <code class="literal">
    mysql
   </code>
   system
      schema:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      For some MySQL installation methods, data directory
          initialization is automatic, as described in
      <a class="xref" href="postinstallation.html" title="2.9 Postinstallation Setup and Testing">
       Section 2.9, “Postinstallation Setup and Testing”
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      For other installation methods, you must initialize the data
          directory manually. These include installation from generic
          binary and source distributions on Unix and Unix-like systems,
          and installation from a ZIP Archive package on Windows.
     </p>
    </li>
   </ul>
  </div>
  <p>
   This section describes how to initialize the data directory
      manually for MySQL installation methods for which data directory
      initialization is not automatic. For some suggested commands that
      enable testing whether the server is accessible and working
      properly, see
   <a class="xref" href="testing-server.html" title="2.9.3 Testing the Server">
    Section 2.9.3, “Testing the Server”
   </a>
   .
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    The default authentication plugin is
    <code class="literal">
     caching_sha2_password
    </code>
    , and the
    <code class="literal">
     'root'@'localhost'
    </code>
    administrative account
        uses
    <code class="literal">
     caching_sha2_password
    </code>
    by default.
   </p>
   <p>
    <a class="link" href="native-pluggable-authentication.html" title="8.4.1.1 Native Pluggable Authentication">
     mysql_native_password
    </a>
    (the default authentication plugin prior to MySQL 8.0) is still
        supported but disabled by default as of MySQL 8.4.0 and removed
        as of MySQL 9.0.0.
   </p>
  </div>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="xref" href="data-directory-initialization.html#data-directory-initialization-overview" title="Data Directory Initialization Overview">
       Data Directory Initialization Overview
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="data-directory-initialization.html#data-directory-initialization-procedure" title="Data Directory Initialization Procedure">
       Data Directory Initialization Procedure
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="data-directory-initialization.html#data-directory-initialization-server-actions" title="Server Actions During Data Directory Initialization">
       Server Actions During Data Directory Initialization
      </a>
     </p>
    </li>
    <li class="listitem">
     <p>
      <a class="xref" href="data-directory-initialization.html#data-directory-initialization-password-assignment" title="Post-Initialization root Password Assignment">
       Post-Initialization root Password Assignment
      </a>
     </p>
    </li>
   </ul>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="data-directory-initialization-overview">
       </a>
       Data Directory Initialization Overview
      </h4>
     </div>
    </div>
   </div>
   <p>
    In the examples shown here, the server is intended to run under
        the user ID of the
    <code class="literal">
     mysql
    </code>
    login account.
        Either create the account if it does not exist (see
    <a class="xref" href="binary-installation.html#binary-installation-createsysuser" title="Create a mysql User and Group">
     Create a mysql User and Group
    </a>
    ), or
        substitute the name of a different existing login account that
        you plan to use for running the server.
   </p>
   <a class="indexterm" name="idm46045327073952">
   </a>
   <a class="indexterm" name="idm46045327072464">
   </a>
   <a class="indexterm" name="idm46045327070976">
   </a>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Change location to the top-level directory of your MySQL
            installation, which is typically
       <code class="filename">
        /usr/local/mysql
       </code>
       (adjust the path name
            for your system as necessary):
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa90223312"><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">cd /usr/local/mysql</code></pre>
      </div>
      <p>
       Within this directory you can find several files and
            subdirectories, including the
       <code class="filename">
        bin
       </code>
       subdirectory that contains the server, as well as client and
            utility programs.
      </p>
     </li>
     <li class="listitem">
      <p>
       The
       <a class="link" href="server-system-variables.html#sysvar_secure_file_priv">
        <code class="literal">
         secure_file_priv
        </code>
       </a>
       system
            variable limits import and export operations to a specific
            directory. Create a directory whose location can be
            specified as the value of that variable:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa23812799"><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">mkdir mysql-files</code></pre>
      </div>
      <p>
       Grant directory user and group ownership to the
       <code class="literal">
        mysql
       </code>
       user and
       <code class="literal">
        mysql
       </code>
       group, and set the directory permissions appropriately:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa47169968"><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">chown mysql<span class="token punctuation">:</span>mysql mysql-files
chmod 750 mysql-files</code></pre>
      </div>
     </li>
     <li class="listitem">
      <p>
       Use the server to initialize the data directory, including
            the
       <code class="literal">
        mysql
       </code>
       schema containing the initial
            MySQL grant tables that determine how users are permitted to
            connect to the server. For example:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa12273579"><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">bin/mysqld <span class="token property">--initialize</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span></code></pre>
      </div>
      <p>
       For important information about the command, especially
            regarding command options you might use, see
       <a class="xref" href="data-directory-initialization.html#data-directory-initialization-procedure" title="Data Directory Initialization Procedure">
        Data Directory Initialization Procedure
       </a>
       .
            For details about how the server performs initialization,
            see
       <a class="xref" href="data-directory-initialization.html#data-directory-initialization-server-actions" title="Server Actions During Data Directory Initialization">
        Server Actions During Data Directory Initialization
       </a>
       .
      </p>
      <p>
       Typically, data directory initialization need be done only
            after you first install MySQL. (For upgrades to an existing
            installation, perform the upgrade procedure instead; see
       <a class="xref" href="upgrading.html" title="Chapter 3 Upgrading MySQL">
        Chapter 3,
        <i>
         Upgrading MySQL
        </i>
       </a>
       .) However, the command that
            initializes the data directory does not overwrite any
            existing
       <code class="literal">
        mysql
       </code>
       schema tables, so it is
            safe to run in any circumstances.
      </p>
     </li>
     <li class="listitem">
      <p>
       In the absence of any option files, the server starts with
            its default settings. (See
       <a class="xref" href="server-configuration-defaults.html" title="7.1.2 Server Configuration Defaults">
        Section 7.1.2, “Server Configuration Defaults”
       </a>
       .) To
            explicitly specify options that the MySQL server should use
            at startup, put them in an option file such as
       <code class="filename">
        /etc/my.cnf
       </code>
       or
       <code class="filename">
        /etc/mysql/my.cnf
       </code>
       . (See
       <a class="xref" href="option-files.html" title="6.2.2.2 Using Option Files">
        Section 6.2.2.2, “Using Option Files”
       </a>
       .) For example, you can use an
            option file to set the
       <a class="link" href="server-system-variables.html#sysvar_secure_file_priv">
        <code class="literal">
         secure_file_priv
        </code>
       </a>
       system
            variable.
      </p>
     </li>
     <li class="listitem">
      <p>
       To arrange for MySQL to start without manual intervention at
            system boot time, see
       <a class="xref" href="automatic-start.html" title="2.9.5 Starting and Stopping MySQL Automatically">
        Section 2.9.5, “Starting and Stopping MySQL Automatically”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       Data directory initialization creates time zone tables in
            the
       <code class="literal">
        mysql
       </code>
       schema but does not populate
            them. To do so, use the instructions in
       <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
        Section 7.1.15, “MySQL Server Time Zone Support”
       </a>
       .
      </p>
     </li>
    </ol>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="data-directory-initialization-procedure">
       </a>
       Data Directory Initialization Procedure
      </h4>
     </div>
    </div>
   </div>
   <p>
    Change location to the top-level directory of your MySQL
        installation, which is typically
    <code class="filename">
     /usr/local/mysql
    </code>
    (adjust the path name for
        your system as necessary):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa63496349"><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">cd /usr/local/mysql</code></pre>
   </div>
   <p>
    To initialize the data directory, invoke
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    with the
    <a class="link" href="server-options.html#option_mysqld_initialize">
     <code class="option">
      --initialize
     </code>
    </a>
    or
    <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
     <code class="option">
      --initialize-insecure
     </code>
    </a>
    option,
        depending on whether you want the server to generate a random
        initial password for the
    <code class="literal">
     'root'@'localhost'
    </code>
    account, or to create that account with no password:
   </p>
   <div class="itemizedlist">
    <ul class="itemizedlist" style="list-style-type: disc; ">
     <li class="listitem">
      <p>
       Use
       <a class="link" href="server-options.html#option_mysqld_initialize">
        <code class="option">
         --initialize
        </code>
       </a>
       for
       <span class="quote">
        “
        <span class="quote">
         secure by default
        </span>
        ”
       </span>
       installation (that is,
            including generation of a random initial
       <code class="literal">
        root
       </code>
       password). In this case, the
            password is marked as expired and you must choose a new one.
      </p>
     </li>
     <li class="listitem">
      <p>
       With
       <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
        <code class="option">
         --initialize-insecure
        </code>
       </a>
       ,
            no
       <code class="literal">
        root
       </code>
       password is generated. This is
            insecure; it is assumed that you intend to assign a password
            to the account in a timely fashion before putting the server
            into production use.
      </p>
     </li>
    </ul>
   </div>
   <p>
    For instructions on assigning a new
    <code class="literal">
     'root'@'localhost'
    </code>
    password, see
    <a class="xref" href="data-directory-initialization.html#data-directory-initialization-password-assignment" title="Post-Initialization root Password Assignment">
     Post-Initialization root Password Assignment
    </a>
    .
   </p>
   <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Note
    </div>
    <p>
     The server writes any messages (including any initial
          password) to its standard error output. This may be redirected
          to the error log, so look there if you do not see the messages
          on your screen. For information about the error log, including
          where it is located, see
     <a class="xref" href="error-log.html" title="7.4.2 The Error Log">
      Section 7.4.2, “The Error Log”
     </a>
     .
    </p>
    <p>
     On Windows, use the
     <a class="link" href="server-options.html#option_mysqld_console">
      <code class="option">
       --console
      </code>
     </a>
     option to direct messages to the console.
    </p>
   </div>
   <p>
    On Unix and Unix-like systems, it is important for the database
        directories and files to be owned by the
    <code class="literal">
     mysql
    </code>
    login account so that the server has
        read and write access to them when you run it later. To ensure
        this, start
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    from the system
    <code class="literal">
     root
    </code>
    account and include the
    <a class="link" href="server-options.html#option_mysqld_user">
     <code class="option">
      --user
     </code>
    </a>
    option as shown here:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa69089509"><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">bin/mysqld <span class="token property">--initialize</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span>
bin/mysqld <span class="token property">--initialize-insecure</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span></code></pre>
   </div>
   <p>
    Alternatively, execute
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    while logged in
        as
    <code class="literal">
     mysql
    </code>
    , in which case you can omit the
    <a class="link" href="server-options.html#option_mysqld_user">
     <code class="option">
      --user
     </code>
    </a>
    option from the command.
   </p>
   <p>
    On Windows, use one of these commands:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa83067570"><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">bin\mysqld <span class="token property">--initialize</span> <span class="token property">--console</span>
bin\mysqld <span class="token property">--initialize-insecure</span> <span class="token property">--console</span></code></pre>
   </div>
   <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Note
    </div>
    <p>
     Data directory initialization might fail if required system
          libraries are missing. For example, you might see an error
          like this:
    </p>
    <div class="copytoclipboard-wrapper">
     <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa55693411"><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">bin/mysqld<span class="token punctuation">:</span> error while loading shared libraries<span class="token punctuation">:</span>
libnuma<span class="token punctuation">.</span>so<span class="token punctuation">.</span>1<span class="token punctuation">:</span> cannot open shared object file<span class="token punctuation">:</span>
No such file or directory</code></pre>
    </div>
    <p>
     If this happens, you must install the missing libraries
          manually or with your system's package manager. Then
          retry the data directory initialization command.
    </p>
   </div>
   <p>
    It might be necessary to specify other options such as
    <a class="link" href="server-system-variables.html#sysvar_basedir">
     <code class="option">
      --basedir
     </code>
    </a>
    or
    <a class="link" href="server-system-variables.html#sysvar_datadir">
     <code class="option">
      --datadir
     </code>
    </a>
    if
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    cannot identify the correct locations
        for the installation directory or data directory. For example
        (enter the command on a single line):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa80670114"><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">bin/mysqld <span class="token property">--initialize</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span>
  <span class="token constant">--basedir</span><span class="token attr-value"><span class="token punctuation">=</span>/opt/mysql/mysql</span>
  <span class="token constant">--datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/opt/mysql/mysql/data</span></code></pre>
   </div>
   <p>
    Alternatively, put the relevant option settings in an option
        file and pass the name of that file to
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    . For Unix and Unix-like systems,
        suppose that the option file name is
    <code class="filename">
     /opt/mysql/mysql/etc/my.cnf
    </code>
    . Put these
        lines in the file:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa73864818"><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">[mysqld]</span>
<span class="token constant">basedir</span><span class="token attr-value"><span class="token punctuation">=</span>/opt/mysql/mysql</span>
<span class="token constant">datadir</span><span class="token attr-value"><span class="token punctuation">=</span>/opt/mysql/mysql/data</span></code></pre>
   </div>
   <p>
    Then invoke
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    as follows (enter the
        command on a single line, with the
    <a class="link" href="option-file-options.html#option_general_defaults-file">
     <code class="option">
      --defaults-file
     </code>
    </a>
    option first):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa83307501"><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">bin/mysqld <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>/opt/mysql/mysql/etc/my.cnf</span>
  <span class="token property">--initialize</span> <span class="token constant">--user</span><span class="token attr-value"><span class="token punctuation">=</span>mysql</span></code></pre>
   </div>
   <p>
    On Windows, suppose that
    <code class="filename">
     C:\my.ini
    </code>
    contains
        these lines:
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa43791165"><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">[mysqld]</span>
<span class="token constant">basedir</span><span class="token attr-value"><span class="token punctuation">=</span>C:\\Program Files\\MySQL\\MySQL Server 8.4</span>
<span class="token constant">datadir</span><span class="token attr-value"><span class="token punctuation">=</span>D:\\MySQLdata</span></code></pre>
   </div>
   <p>
    Then invoke
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    as follows (again, you
        should enter the command on a single line, with the
    <a class="link" href="option-file-options.html#option_general_defaults-file">
     <code class="option">
      --defaults-file
     </code>
    </a>
    option first):
   </p>
   <div class="copytoclipboard-wrapper">
    <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa35560823"><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">bin\mysqld <span class="token constant">--defaults-file</span><span class="token attr-value"><span class="token punctuation">=</span>C:\my.ini</span>
   <span class="token property">--initialize</span> <span class="token property">--console</span></code></pre>
   </div>
   <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Important
    </div>
    <p>
     When initializing the data directory, you should not specify
          any options other than those used for setting directory
          locations such as
     <a class="link" href="server-system-variables.html#sysvar_basedir">
      <code class="option">
       --basedir
      </code>
     </a>
     or
     <a class="link" href="server-system-variables.html#sysvar_datadir">
      <code class="option">
       --datadir
      </code>
     </a>
     , and the
     <a class="link" href="server-options.html#option_mysqld_user">
      <code class="option">
       --user
      </code>
     </a>
     option if needed.
          Options to be employed by the MySQL server during normal use
          can be set when restarting it following initialization. See
          the description of the
     <a class="link" href="server-options.html#option_mysqld_initialize">
      <code class="option">
       --initialize
      </code>
     </a>
     option for further
          information.
    </p>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="data-directory-initialization-server-actions">
       </a>
       Server Actions During Data Directory Initialization
      </h4>
     </div>
    </div>
   </div>
   <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Note
    </div>
    <p>
     The data directory initialization sequence performed by the
          server does not substitute for the actions performed by
     <a class="link" href="mysql-secure-installation.html" title="6.4.2 mysql_secure_installation — Improve MySQL Installation Security">
      <span class="command">
       <strong>
        mysql_secure_installation
       </strong>
      </span>
     </a>
     .
    </p>
   </div>
   <p>
    When invoked with the
    <a class="link" href="server-options.html#option_mysqld_initialize">
     <code class="option">
      --initialize
     </code>
    </a>
    or
    <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
     <code class="option">
      --initialize-insecure
     </code>
    </a>
    option,
    <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
     <span class="command">
      <strong>
       mysqld
      </strong>
     </span>
    </a>
    performs the following actions during
        the data directory initialization sequence:
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       The server checks for the existence of the data directory as
            follows:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: disc; ">
        <li class="listitem">
         <p>
          If no data directory exists, the server creates it.
         </p>
        </li>
        <li class="listitem">
         <p>
          If the data directory exists but is not empty (that is,
                it contains files or subdirectories), the server exits
                after producing an error message:
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa4231181"><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-none">[ERROR] --initialize specified but the data directory exists. Aborting.</code></pre>
         </div>
         <p>
          In this case, remove or rename the data directory and
                try again.
         </p>
         <p>
          An existing data directory is permitted to be nonempty
                if every entry has a name that begins with a period
                (
          <code class="literal">
           .
          </code>
          ).
         </p>
        </li>
       </ul>
      </div>
     </li>
     <li class="listitem">
      <p>
       Within the data directory, the server creates the
       <code class="literal">
        mysql
       </code>
       system schema and its tables,
            including the data dictionary tables, grant tables, time
            zone tables, and server-side help tables. See
       <a class="xref" href="system-schema.html" title="7.3 The mysql System Schema">
        Section 7.3, “The mysql System Schema”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The server initializes the
       <a class="link" href="glossary.html#glos_system_tablespace" title="system tablespace">
        system
            tablespace
       </a>
       and related data structures needed to
            manage
       <a class="link" href="innodb-storage-engine.html" title="Chapter 17 The InnoDB Storage Engine">
        <code class="literal">
         InnoDB
        </code>
       </a>
       tables.
      </p>
      <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
       <div class="admon-title">
        Note
       </div>
       <p>
        After
        <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
         <span class="command">
          <strong>
           mysqld
          </strong>
         </span>
        </a>
        sets up the
        <code class="literal">
         InnoDB
        </code>
        <a class="link" href="glossary.html#glos_system_tablespace" title="system tablespace">
         system
              tablespace
        </a>
        , certain changes to tablespace
              characteristics require setting up a whole new
        <a class="link" href="glossary.html#glos_instance" title="instance">
         instance
        </a>
        . Qualifying
              changes include the file name of the first file in the
              system tablespace and the number of undo logs. If you do
              not want to use the default values, make sure that the
              settings for the
        <a class="link" href="innodb-parameters.html#sysvar_innodb_data_file_path">
         <code class="literal">
          innodb_data_file_path
         </code>
        </a>
        and
        <a class="link" href="innodb-parameters.html#sysvar_innodb_log_file_size">
         <code class="literal">
          innodb_log_file_size
         </code>
        </a>
        configuration parameters are in place in the MySQL
        <a class="link" href="glossary.html#glos_configuration_file" title="configuration file">
         configuration
              file
        </a>
        <span class="emphasis">
         <em>
          before
         </em>
        </span>
        running
        <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
         <span class="command">
          <strong>
           mysqld
          </strong>
         </span>
        </a>
        . Also make sure to specify as
              necessary other parameters that affect the creation and
              location of
        <code class="literal">
         InnoDB
        </code>
        files, such as
        <a class="link" href="innodb-parameters.html#sysvar_innodb_data_home_dir">
         <code class="literal">
          innodb_data_home_dir
         </code>
        </a>
        and
        <a class="link" href="innodb-parameters.html#sysvar_innodb_log_group_home_dir">
         <code class="literal">
          innodb_log_group_home_dir
         </code>
        </a>
        .
       </p>
       <p>
        If those options are in your configuration file but that
              file is not in a location that MySQL reads by default,
              specify the file location using the
        <a class="link" href="server-options.html#option_mysqld_defaults-extra-file">
         <code class="option">
          --defaults-extra-file
         </code>
        </a>
        option when you run
        <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
         <span class="command">
          <strong>
           mysqld
          </strong>
         </span>
        </a>
        .
       </p>
      </div>
     </li>
     <li class="listitem">
      <p>
       The server creates a
       <code class="literal">
        'root'@'localhost'
       </code>
       superuser account and other reserved accounts (see
       <a class="xref" href="reserved-accounts.html" title="8.2.9 Reserved Accounts">
        Section 8.2.9, “Reserved Accounts”
       </a>
       ). Some reserved accounts
            are locked and cannot be used by clients, but
       <code class="literal">
        'root'@'localhost'
       </code>
       is intended for
            administrative use and you should assign it a password.
      </p>
      <p>
       Server actions with respect to a password for the
       <code class="literal">
        'root'@'localhost'
       </code>
       account depend on how
            you invoke it:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: disc; ">
        <li class="listitem">
         <p>
          With
          <a class="link" href="server-options.html#option_mysqld_initialize">
           <code class="option">
            --initialize
           </code>
          </a>
          but not
          <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
           <code class="option">
            --initialize-insecure
           </code>
          </a>
          ,
                the server generates a random password, marks it as
                expired, and writes a message displaying the password:
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting language-none"><div class="docs-select-all right" id="sa62666523"><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-none">[Warning] A temporary password is generated for root@localhost:
iTag*AfrH5ej</code></pre>
         </div>
        </li>
        <li class="listitem">
         <p>
          With
          <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
           <code class="option">
            --initialize-insecure
           </code>
          </a>
          ,
                (either with or without
          <a class="link" href="server-options.html#option_mysqld_initialize">
           <code class="option">
            --initialize
           </code>
          </a>
          because
          <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
           <code class="option">
            --initialize-insecure
           </code>
          </a>
          implies
          <a class="link" href="server-options.html#option_mysqld_initialize">
           <code class="option">
            --initialize
           </code>
          </a>
          ),
                the server does not generate a password or mark it
                expired, and writes a warning message:
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting language-none"><div class="docs-select-all right" id="sa3187855"><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-none">[Warning] root@localhost is created with an empty password ! Please
consider switching off the --initialize-insecure option.</code></pre>
         </div>
        </li>
       </ul>
      </div>
      <p>
       For instructions on assigning a new
       <code class="literal">
        'root'@'localhost'
       </code>
       password, see
       <a class="xref" href="data-directory-initialization.html#data-directory-initialization-password-assignment" title="Post-Initialization root Password Assignment">
        Post-Initialization root Password Assignment
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       The server populates the server-side help tables used for
            the
       <a class="link" href="help.html" title="15.8.3 HELP Statement">
        <code class="literal">
         HELP
        </code>
       </a>
       statement (see
       <a class="xref" href="help.html" title="15.8.3 HELP Statement">
        Section 15.8.3, “HELP Statement”
       </a>
       ). The server does not populate the
            time zone tables. To do so manually, see
       <a class="xref" href="time-zone-support.html" title="7.1.15 MySQL Server Time Zone Support">
        Section 7.1.15, “MySQL Server Time Zone Support”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       If the
       <a class="link" href="server-system-variables.html#sysvar_init_file">
        <code class="literal">
         init_file
        </code>
       </a>
       system
            variable was given to name a file of SQL statements, the
            server executes the statements in the file. This option
            enables you to perform custom bootstrapping sequences.
      </p>
      <p>
       When the server operates in bootstrap mode, some
            functionality is unavailable that limits the statements
            permitted in the file. These include statements that relate
            to account management (such as
       <a class="link" href="create-user.html" title="15.7.1.3 CREATE USER Statement">
        <code class="literal">
         CREATE
            USER
        </code>
       </a>
       or
       <a class="link" href="grant.html" title="15.7.1.6 GRANT Statement">
        <code class="literal">
         GRANT
        </code>
       </a>
       ),
            replication, and global transaction identifiers.
      </p>
     </li>
     <li class="listitem">
      <p>
       The server exits.
      </p>
     </li>
    </ol>
   </div>
  </div>
  <div class="simplesect">
   <div class="titlepage">
    <div>
     <div class="simple">
      <h4 class="title">
       <a name="data-directory-initialization-password-assignment">
       </a>
       Post-Initialization root Password Assignment
      </h4>
     </div>
    </div>
   </div>
   <p>
    After you initialize the data directory by starting the server
        with
    <a class="link" href="server-options.html#option_mysqld_initialize">
     <code class="option">
      --initialize
     </code>
    </a>
    or
    <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
     <code class="option">
      --initialize-insecure
     </code>
    </a>
    , start the
        server normally (that is, without either of those options) and
        assign the
    <code class="literal">
     'root'@'localhost'
    </code>
    account a new
        password:
   </p>
   <div class="orderedlist">
    <ol class="orderedlist" type="1">
     <li class="listitem">
      <p>
       Start the server. For instructions, see
       <a class="xref" href="starting-server.html" title="2.9.2 Starting the Server">
        Section 2.9.2, “Starting the Server”
       </a>
       .
      </p>
     </li>
     <li class="listitem">
      <p>
       Connect to the server:
      </p>
      <div class="itemizedlist">
       <ul class="itemizedlist" style="list-style-type: disc; ">
        <li class="listitem">
         <p>
          If you used
          <a class="link" href="server-options.html#option_mysqld_initialize">
           <code class="option">
            --initialize
           </code>
          </a>
          but not
          <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
           <code class="option">
            --initialize-insecure
           </code>
          </a>
          to
                initialize the data directory, connect to the server as
          <code class="literal">
           root
          </code>
          :
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa63561512"><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">mysql <span class="token property">-u</span> root <span class="token property">-p</span></code></pre>
         </div>
         <p>
          Then, at the password prompt, enter the random password
                that the server generated during the initialization
                sequence:
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa6595132"><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-none">Enter password: <em class="replaceable">(enter the random root password here)</em></code></pre>
         </div>
         <p>
          Look in the server error log if you do not know this
                password.
         </p>
        </li>
        <li class="listitem">
         <p>
          If you used
          <a class="link" href="server-options.html#option_mysqld_initialize-insecure">
           <code class="option">
            --initialize-insecure
           </code>
          </a>
          to
                initialize the data directory, connect to the server as
          <code class="literal">
           root
          </code>
          without a password:
         </p>
         <div class="copytoclipboard-wrapper">
          <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa45198081"><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">mysql <span class="token property">-u</span> root <span class="token property">--skip-password</span></code></pre>
         </div>
        </li>
       </ul>
      </div>
     </li>
     <li class="listitem">
      <p>
       After connecting, use an
       <a class="link" href="alter-user.html" title="15.7.1.1 ALTER USER Statement">
        <code class="literal">
         ALTER
            USER
        </code>
       </a>
       statement to assign a new
       <code class="literal">
        root
       </code>
       password:
      </p>
      <div class="copytoclipboard-wrapper">
       <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa71794246"><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">ALTER</span> <span class="token keyword">USER</span> <span class="token string">'root'</span>@<span class="token string">'localhost'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">root-password'</em></span><span class="token punctuation">;</span></code></pre>
      </div>
     </li>
    </ol>
   </div>
   <p>
    See also
    <a class="xref" href="default-privileges.html" title="2.9.4 Securing the Initial MySQL Account">
     Section 2.9.4, “Securing the Initial MySQL Account”
    </a>
    .
   </p>
   <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
    <div class="admon-title">
     Note
    </div>
    <p>
     Attempts to connect to the host
     <code class="literal">
      127.0.0.1
     </code>
     normally resolve to the
     <code class="literal">
      localhost
     </code>
     account.
          However, this fails if the server is run with
     <a class="link" href="server-system-variables.html#sysvar_skip_name_resolve">
      <code class="literal">
       skip_name_resolve
      </code>
     </a>
     enabled. If
          you plan to do that, make sure that an account exists that can
          accept a connection. For example, to be able to connect as
     <code class="literal">
      root
     </code>
     using
     <code class="option">
      --host=127.0.0.1
     </code>
     or
     <code class="option">
      --host=::1
     </code>
     , create these accounts:
    </p>
    <div class="copytoclipboard-wrapper">
     <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa46116313"><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">USER</span> <span class="token string">'root'</span>@<span class="token string">'127.0.0.1'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">root-password</em>'</span><span class="token punctuation">;</span>
<span class="token keyword">CREATE</span> <span class="token keyword">USER</span> <span class="token string">'root'</span>@<span class="token string">'::1'</span> <span class="token keyword">IDENTIFIED</span> <span class="token keyword">BY</span> <span class="token string">'<em class="replaceable">root-password</em>'</span><span class="token punctuation">;</span></code></pre>
    </div>
    <p>
     It is possible to put those statements in a file to be
          executed using the
     <a class="link" href="server-system-variables.html#sysvar_init_file">
      <code class="literal">
       init_file
      </code>
     </a>
     system variable, as discussed in
     <a class="xref" href="data-directory-initialization.html#data-directory-initialization-server-actions" title="Server Actions During Data Directory Initialization">
      Server Actions During Data Directory Initialization
     </a>
     .
    </p>
   </div>
  </div>
 </div>
 <br/>
</div>
