<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="windows-symbolic-links">
      </a>
      10.12.2.3 Using Symbolic Links for Databases on Windows
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045222402272">
  </a>
  <a class="indexterm" name="idm46045222401232">
  </a>
  <a class="indexterm" name="idm46045222399744">
  </a>
  <a class="indexterm" name="idm46045222398656">
  </a>
  <p>
   On Windows, symbolic links can be used for database
          directories. This enables you to put a database directory at a
          different location (for example, on a different disk) by
          setting up a symbolic link to it. Use of database symlinks on
          Windows is similar to their use on Unix, although the
          procedure for setting up the link differs.
  </p>
  <p>
   Suppose that you want to place the database directory for a
          database named
   <code class="literal">
    mydb
   </code>
   at
   <code class="filename">
    D:\data\mydb
   </code>
   . To do this, create a
          symbolic link in the MySQL data directory that points to
   <code class="filename">
    D:\data\mydb
   </code>
   . However, before creating
          the symbolic link, make sure that the
   <code class="filename">
    D:\data\mydb
   </code>
   directory exists by creating
          it if necessary. If you already have a database directory
          named
   <code class="filename">
    mydb
   </code>
   in the data directory, move it
          to
   <code class="filename">
    D:\data
   </code>
   . Otherwise, the symbolic link
          has no effect. To avoid problems, make sure that the server is
          not running when you move the database directory.
  </p>
  <p>
   On Windows, you can create a symlink using the
   <span class="command">
    <strong>
     mklink
    </strong>
   </span>
   command. This command
          requires administrative privileges.
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Make sure that the desired path to the database exists.
              For this example, we use
      <code class="filename">
       D:\data\mydb
      </code>
      , and a database named
      <code class="literal">
       mydb
      </code>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      If the database does not already exist, issue
      <code class="literal">
       CREATE DATABASE mydb
      </code>
      in 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 create it.
     </p>
    </li>
    <li class="listitem">
     <p>
      Stop the MySQL service.
     </p>
    </li>
    <li class="listitem">
     <p>
      Using Windows Explorer or the command line, move the
              directory
      <code class="filename">
       mydb
      </code>
      from the data
              directory to
      <code class="filename">
       D:\data
      </code>
      , replacing the
              directory of the same name.
     </p>
    </li>
    <li class="listitem">
     <p>
      If you are not already using the command prompt, open it,
              and change location to the data directory, like this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa82269575"><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"> cd</span> <em class="replaceable">\path\to\datadir</em></code></pre>
     </div>
     <p>
      If your MySQL installation is in the default location, you
              can use this:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa60688621"><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"> cd</span> C<span class="token punctuation">:</span>\ProgramData\MySQL\MySQL Server 8<span class="token punctuation">.</span>4\Data</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      In the data directory, create a symlink named
      <code class="filename">
       mydb
      </code>
      that points to the location of
              the database directory:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa6383972"><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"> mklink</span> /d mydb D<span class="token punctuation">:</span>\data\mydb</code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      Start the MySQL service.
     </p>
    </li>
   </ol>
  </div>
  <p>
   After this, all tables created in the database
   <code class="literal">
    mydb
   </code>
   are created in
   <code class="filename">
    D:\data\mydb
   </code>
   .
  </p>
  <p>
   Alternatively, on any version of Windows supported by MySQL,
          you can create a symbolic link to a MySQL database by creating
          a
   <code class="filename">
    .sym
   </code>
   file in the data directory that
          contains the path to the destination directory. The file
          should be named
   <code class="filename">
    <em class="replaceable">
     <code>
      db_name
     </code>
    </em>
    .sym
   </code>
   ,
          where
   <em class="replaceable">
    <code>
     db_name
    </code>
   </em>
   is the database name.
  </p>
  <p>
   Support for database symbolic links on Windows using
   <code class="filename">
    .sym
   </code>
   files is enabled by default. If you
          do not need
   <code class="filename">
    .sym
   </code>
   file symbolic links, you
          can disable support for them by starting
   <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_symbolic-links">
    <code class="option">
     --skip-symbolic-links
    </code>
   </a>
   option. To determine whether your system supports
   <code class="filename">
    .sym
   </code>
   file symbolic links, check the value
          of the
   <a class="link" href="server-system-variables.html#sysvar_have_symlink">
    <code class="literal">
     have_symlink
    </code>
   </a>
   system
          variable using this statement:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa34010028"><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">VARIABLES</span> <span class="token operator">LIKE</span> <span class="token string">'have_symlink'</span><span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   To create a
   <code class="filename">
    .sym
   </code>
   file symlink, use this
          procedure:
  </p>
  <div class="orderedlist">
   <ol class="orderedlist" type="1">
    <li class="listitem">
     <p>
      Change location into the data directory:
     </p>
     <div class="copytoclipboard-wrapper">
      <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa6468634"><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"> cd</span> <em class="replaceable">\path\to\datadir</em></code></pre>
     </div>
    </li>
    <li class="listitem">
     <p>
      In the data directory, create a text file named
      <code class="filename">
       mydb.sym
      </code>
      that contains this path
              name:
      <code class="literal">
       D:\data\mydb\
      </code>
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The path name to the new database and tables should be
                absolute. If you specify a relative path, the location
                is relative to the
       <code class="filename">
        mydb.sym
       </code>
       file.
      </p>
     </div>
    </li>
   </ol>
  </div>
  <p>
   After this, all tables created in the database
   <code class="literal">
    mydb
   </code>
   are created in
   <code class="filename">
    D:\data\mydb
   </code>
   .
  </p>
 </div>
 <br/>
</div>
