<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="myisam-table-close">
      </a>
      18.2.4.2 Problems from Tables Not Being Closed Properly
     </h4>
    </div>
   </div>
  </div>
  <p>
   Each
   <code class="literal">
    MyISAM
   </code>
   index file
        (
   <code class="filename">
    .MYI
   </code>
   file) has a counter in the header
        that can be used to check whether a table has been closed
        properly. If you get the following warning from
   <a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
    <code class="literal">
     CHECK TABLE
    </code>
   </a>
   or
   <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
    <span class="command">
     <strong>
      myisamchk
     </strong>
    </span>
   </a>
   , it means that this counter has
        gone out of sync:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-none"><div class="docs-select-all right" id="sa63213416"><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">clients are using or haven't closed the table properly</code></pre>
  </div>
  <p>
   This warning doesn't necessarily mean that the table is
        corrupted, but you should at least check the table.
  </p>
  <p>
   The counter works as follows:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      The first time a table is updated in MySQL, a counter in the
            header of the index files is incremented.
     </p>
    </li>
    <li class="listitem">
     <p>
      The counter is not changed during further updates.
     </p>
    </li>
    <li class="listitem">
     <p>
      When the last instance of a table is closed (because a
      <a class="link" href="flush.html#flush-tables">
       <code class="literal">
        FLUSH TABLES
       </code>
      </a>
      operation was
            performed or because there is no room in the table cache),
            the counter is decremented if the table has been updated at
            any point.
     </p>
    </li>
    <li class="listitem">
     <p>
      When you repair the table or check the table and it is found
            to be okay, the counter is reset to zero.
     </p>
    </li>
    <li class="listitem">
     <p>
      To avoid problems with interaction with other processes that
            might check the table, the counter is not decremented on
            close if it was zero.
     </p>
    </li>
   </ul>
  </div>
  <p>
   In other words, the counter can become incorrect only under
        these conditions:
  </p>
  <div class="itemizedlist">
   <ul class="itemizedlist" style="list-style-type: disc; ">
    <li class="listitem">
     <p>
      A
      <code class="literal">
       MyISAM
      </code>
      table is copied without first
            issuing
      <a class="link" href="lock-tables.html" title="15.3.6 LOCK TABLES and UNLOCK TABLES Statements">
       <code class="literal">
        LOCK TABLES
       </code>
      </a>
      and
      <a class="link" href="flush.html#flush-tables">
       <code class="literal">
        FLUSH TABLES
       </code>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      MySQL has crashed between an update and the final close.
            (The table may still be okay because MySQL always issues
            writes for everything between each statement.)
     </p>
    </li>
    <li class="listitem">
     <p>
      A table was modified by
      <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
       <span class="command">
        <strong>
         myisamchk
            --recover
        </strong>
       </span>
      </a>
      or
      <a class="link" href="myisamchk.html" title="6.6.4 myisamchk — MyISAM Table-Maintenance Utility">
       <span class="command">
        <strong>
         myisamchk
            --update-state
        </strong>
       </span>
      </a>
      at the same time that it was in use
            by
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      .
     </p>
    </li>
    <li class="listitem">
     <p>
      Multiple
      <a class="link" href="mysqld.html" title="6.3.1 mysqld — The MySQL Server">
       <span class="command">
        <strong>
         mysqld
        </strong>
       </span>
      </a>
      servers are using the
            table and one server performed a
      <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
       <code class="literal">
        REPAIR
            TABLE
       </code>
      </a>
      or
      <a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
       <code class="literal">
        CHECK
            TABLE
       </code>
      </a>
      on the table while it was in use by another
            server. In this setup, it is safe to use
      <a class="link" href="check-table.html" title="15.7.3.2 CHECK TABLE Statement">
       <code class="literal">
        CHECK TABLE
       </code>
      </a>
      , although you
            might get the warning from other servers. However,
      <a class="link" href="repair-table.html" title="15.7.3.5 REPAIR TABLE Statement">
       <code class="literal">
        REPAIR TABLE
       </code>
      </a>
      should be
            avoided because when one server replaces the data file with
            a new one, this is not known to the other servers.
     </p>
     <p>
      In general, it is a bad idea to share a data directory among
            multiple servers. See
      <a class="xref" href="multiple-servers.html" title="7.8 Running Multiple MySQL Instances on One Machine">
       Section 7.8, “Running Multiple MySQL Instances on One Machine”
      </a>
      ,
            for additional discussion.
     </p>
    </li>
   </ul>
  </div>
 </div>
 <br/>
</div>
