<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="apache">
      </a>
      5.7 Using MySQL with Apache
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045324499680">
  </a>
  <p>
   There are programs that let you authenticate your users from a
      MySQL database and also let you write your log files into a MySQL
      table.
  </p>
  <p>
   You can change the Apache logging format to be easily readable by
      MySQL by putting the following into the Apache configuration file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-none"><div class="docs-select-all right" id="sa57392319"><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">LogFormat \
        "\"%h\",%{%Y%m%d%H%M%S}t,%&gt;s,\"%b\",\"%{Content-Type}o\",  \
        \"%U\",\"%{Referer}i\",\"%{User-Agent}i\""</code></pre>
  </div>
  <p>
   To load a log file in that format into MySQL, you can use a
      statement something like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa64379494"><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">LOAD</span> <span class="token keyword">DATA</span> <span class="token keyword">INFILE</span> <span class="token string">'<em class="replaceable">/local/access_log</em>'</span> <span class="token keyword">INTO</span> <span class="token keyword">TABLE</span> <em class="replaceable">tbl_name</em>
<span class="token keyword">FIELDS</span> <span class="token keyword">TERMINATED</span> <span class="token keyword">BY</span> <span class="token string">','</span> <span class="token keyword">OPTIONALLY</span> <span class="token keyword">ENCLOSED</span> <span class="token keyword">BY</span> <span class="token string">'"'</span> <span class="token keyword">ESCAPED</span> <span class="token keyword">BY</span> <span class="token string">'\\'</span></code></pre>
  </div>
  <p>
   The named table should be created to have columns that correspond
      to those that the
   <code class="literal">
    LogFormat
   </code>
   line writes to the
      log file.
  </p>
 </div>
 <br/>
</div>
