<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="symbolic-links-to-tables">
      </a>
      10.12.2.2 Using Symbolic Links for MyISAM Tables on Unix
     </h4>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045222456288">
  </a>
  <a class="indexterm" name="idm46045222454800">
  </a>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    Symbolic link support as described here, along with the
    <a class="link" href="server-options.html#option_mysqld_symbolic-links">
     <code class="option">
      --symbolic-links
     </code>
    </a>
    option that
            controls it, and is deprecated; expect these to be removed
            in a future version of MySQL. In addition, the option is
            disabled by default.
   </p>
  </div>
  <p>
   Symlinks are fully supported only for
   <code class="literal">
    MyISAM
   </code>
   tables. For files used by tables for
          other storage engines, you may get strange problems if you try
          to use symbolic links. For
   <code class="literal">
    InnoDB
   </code>
   tables,
          use the alternative technique explained in
   <a class="xref" href="innodb-create-table-external.html" title="17.6.1.2 Creating Tables Externally">
    Section 17.6.1.2, “Creating Tables Externally”
   </a>
   instead.
  </p>
  <p>
   Do not symlink tables on systems that do not have a fully
          operational
   <code class="literal">
    realpath()
   </code>
   call. (Linux and
          Solaris support
   <code class="literal">
    realpath()
   </code>
   ). To determine
          whether your system supports 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="sa38333477"><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>
   The handling of symbolic links for
   <code class="literal">
    MyISAM
   </code>
   tables works as follows:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      In the data directory, you always have the data
              (
      <code class="filename">
       .MYD
      </code>
      ) file and the index
              (
      <code class="filename">
       .MYI
      </code>
      ) file. The data file and index
              file can be moved elsewhere and replaced in the data
              directory by symlinks.
     </p>
    </li>
    <li class="listitem">
     <p>
      You can symlink the data file and the index file
              independently to different directories.
     </p>
    </li>
    <li class="listitem">
     <p>
      To instruct a running MySQL server to perform the
              symlinking, use the
      <code class="literal">
       DATA DIRECTORY
      </code>
      and
      <code class="literal">
       INDEX DIRECTORY
      </code>
      options to
      <a class="link" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       <code class="literal">
        CREATE TABLE
       </code>
      </a>
      . See
      <a class="xref" href="create-table.html" title="15.1.20 CREATE TABLE Statement">
       Section 15.1.20, “CREATE TABLE Statement”
      </a>
      . Alternatively, if
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      is not running, symlinking can
              be accomplished manually using
      <span class="command">
       <strong>
        ln -s
       </strong>
      </span>
      from the command line.
     </p>
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       The path used with either or both of the
       <code class="literal">
        DATA
                DIRECTORY
       </code>
       and
       <code class="literal">
        INDEX
                DIRECTORY
       </code>
       options may not include the MySQL
       <code class="literal">
        data
       </code>
       directory. (Bug #32167)
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
       <span class="command">
        <strong>
         myisamchk
        </strong>
       </span>
      </a>
      does not replace a symlink
              with the data file or index file. It works directly on the
              file to which the symlink points. Any temporary files are
              created in the directory where the data file or index file
              is located. The same is true for the
      <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
       <code class="literal">
        ALTER TABLE
       </code>
      </a>
      ,
      <a class="link" href="optimize-table.html" title="15.7.3.4 OPTIMIZE TABLE Statement">
       <code class="literal">
        OPTIMIZE TABLE
       </code>
      </a>
      , and
      <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
       <code class="literal">
        REPAIR TABLE
       </code>
      </a>
      statements.
     </p>
    </li>
    <li class="listitem">
     <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
      <div class="admon-title">
       Note
      </div>
      <p>
       When you drop a table that is using symlinks,
       <span class="emphasis">
        <em>
         both the symlink and the file to which the
                symlink points are dropped
        </em>
       </span>
       . This is an
                extremely good reason
       <span class="emphasis">
        <em>
         not
        </em>
       </span>
       to run
       <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
        <span class="command">
         <strong>
          mysqld
         </strong>
        </span>
       </a>
       as the
       <code class="literal">
        root
       </code>
       operating system user or permit operating system users
                to have write access to MySQL database directories.
      </p>
     </div>
    </li>
    <li class="listitem">
     <p>
      If you rename a table with
      <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
       <code class="literal">
        ALTER TABLE
              ... RENAME
       </code>
      </a>
      or
      <a class="link" href="rename-table.html" title="15.1.36 RENAME TABLE Statement">
       <code class="literal">
        RENAME
              TABLE
       </code>
      </a>
      and you do not move the table to another
              database, the symlinks in the database directory are
              renamed to the new names and the data file and index file
              are renamed accordingly.
     </p>
    </li>
    <li class="listitem">
     <p>
      If you use
      <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
       <code class="literal">
        ALTER TABLE
              ... RENAME
       </code>
      </a>
      or
      <a class="link" href="rename-table.html" title="15.1.36 RENAME TABLE Statement">
       <code class="literal">
        RENAME
              TABLE
       </code>
      </a>
      to move a table to another database, the
              table is moved to the other database directory. If the
              table name changed, the symlinks in the new database
              directory are renamed to the new names and the data file
              and index file are renamed accordingly.
     </p>
    </li>
    <li class="listitem">
     <p>
      If you are not using symlinks, start
      <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 ensure that no one can use
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      to drop or rename a file outside
              of the data directory.
     </p>
    </li>
   </ul>
  </div>
  <p>
   These table symlink operations are not supported:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      <a class="link" href="alter-table.html" title="15.1.9 ALTER TABLE Statement">
       <code class="literal">
        ALTER TABLE
       </code>
      </a>
      ignores the
      <code class="literal">
       DATA DIRECTORY
      </code>
      and
      <code class="literal">
       INDEX
              DIRECTORY
      </code>
      table options.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
