<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="windows-create-option-file">
      </a>
      2.3.3.2 Creating an Option File
     </h4>
    </div>
   </div>
  </div>
  <p>
   If you need to specify startup options when you run the server,
        you can indicate them on the command line or place them in an
        option file. For options that are used every time the server
        starts, you may find it most convenient to use an option file to
        specify your MySQL configuration. This is particularly true
        under the following circumstances:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The installation or data directory locations are different
            from the default locations (
      <code class="filename">
       C:\Program
            Files\MySQL\MySQL Server 8.4
      </code>
      and
      <code class="filename">
       C:\Program Files\MySQL\MySQL Server
            8.4\data
      </code>
      ).
     </p>
    </li>
    <li class="listitem">
     <p>
      You need to tune the server settings, such as memory, cache,
            or InnoDB configuration information.
     </p>
    </li>
   </ul>
  </div>
  <p>
   When the MySQL server starts on Windows, it looks for option
        files in several locations, such as the Windows directory,
   <code class="filename">
    C:\
   </code>
   , and the MySQL installation directory
        (for the full list of locations, 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>
   ). The Windows directory typically
        is named something like
   <code class="filename">
    C:\WINDOWS
   </code>
   . You can
        determine its exact location from the value of the
   <code class="literal">
    WINDIR
   </code>
   environment variable using the
        following command:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa94356362"><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">C:\&gt;</span><span class="token command"> echo</span> %WINDIR%</code></pre>
  </div>
  <p>
   MySQL looks for options in each location first in the
   <code class="filename">
    my.ini
   </code>
   file, and then in the
   <code class="filename">
    my.cnf
   </code>
   file. However, to avoid confusion,
        it is best if you use only one file. If your PC uses a boot
        loader where
   <code class="filename">
    C:
   </code>
   is not the boot drive, your
        only option is to use the
   <code class="filename">
    my.ini
   </code>
   file.
        Whichever option file you use, it must be a plain text file.
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    When using MySQL Configurator to configure MySQL Server, it creates the
    <code class="filename">
     my.ini
    </code>
    at the default location, and the
          user executing MySQL Configurator is granted full permissions to this
          new
    <code class="filename">
     my.ini
    </code>
    file.
   </p>
   <p>
    In other words, be sure that the MySQL Server user has
          permission to read the
    <code class="filename">
     my.ini
    </code>
    file.
   </p>
  </div>
  <p>
   You can also make use of the example option files included with
        your MySQL distribution; see
   <a class="xref" href="server-configuration-defaults.html" title="7.1.2 Server Configuration Defaults">
    Section 7.1.2, “Server Configuration Defaults”
   </a>
   .
  </p>
  <p>
   An option file can be created and modified with any text editor,
        such as Notepad. For example, if MySQL is installed in
   <code class="filename">
    E:\mysql
   </code>
   and the data directory is in
   <code class="filename">
    E:\mydata\data
   </code>
   , you can create an option
        file containing a
   <code class="literal">
    [mysqld]
   </code>
   section to specify
        values for the
   <code class="option">
    basedir
   </code>
   and
   <code class="option">
    datadir
   </code>
   options:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa11459252"><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 comment" spellcheck="true"># set basedir to your installation path</span>
<span class="token constant">basedir</span><span class="token attr-value"><span class="token punctuation">=</span>E:/mysql</span>
<span class="token comment" spellcheck="true"># set datadir to the location of your data directory</span>
<span class="token constant">datadir</span><span class="token attr-value"><span class="token punctuation">=</span>E:/mydata/data</span></code></pre>
  </div>
  <p>
   Microsoft Windows path names are specified in option files using
        (forward) slashes rather than backslashes. If you do use
        backslashes, double them:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-ini"><div class="docs-select-all right" id="sa80010762"><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 comment" spellcheck="true"># set basedir to your installation path</span>
<span class="token constant">basedir</span><span class="token attr-value"><span class="token punctuation">=</span>E:\\mysql</span>
<span class="token comment" spellcheck="true"># set datadir to the location of your data directory</span>
<span class="token constant">datadir</span><span class="token attr-value"><span class="token punctuation">=</span>E:\\mydata\\data</span></code></pre>
  </div>
  <p>
   The rules for use of backslash in option file values are given
        in
   <a class="xref" href="option-files.html" title="6.2.2.2 Using Option Files">
    Section 6.2.2.2, “Using Option Files”
   </a>
   .
  </p>
  <p>
   The ZIP archive does not include a
   <code class="filename">
    data
   </code>
   directory. To initialize a MySQL installation by creating the
        data directory and populating the tables in the mysql system
        database, initialize MySQL using either
   <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>
   . For
        additional information, see
   <a class="xref" href="data-directory-initialization.html" title="2.9.1 Initializing the Data Directory">
    Section 2.9.1, “Initializing the Data Directory”
   </a>
   .
  </p>
  <p>
   If you would like to use a data directory in a different
        location, you should copy the entire contents of the
   <code class="filename">
    data
   </code>
   directory to the new location. For
        example, if you want to use
   <code class="filename">
    E:\mydata
   </code>
   as
        the data directory instead, you must do two things:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Move the entire
      <code class="filename">
       data
      </code>
      directory and all
            of its contents from the default location (for example
      <code class="filename">
       C:\Program Files\MySQL\MySQL Server
            8.4\data
      </code>
      ) to
      <code class="filename">
       E:\mydata
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      Use a
      <a class="link" href="server-system-variables.html#sysvar_datadir">
       <code class="option">
        --datadir
       </code>
      </a>
      option to
            specify the new data directory location each time you start
            the server.
     </p>
    </li>
   </ol>
  </div>
 </div>
 <br/>
</div>
