<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="csv-storage-engine">
      </a>
      18.4 The CSV Storage Engine
     </h2>
    </div>
   </div>
  </div>
  <div class="toc">
   <dl class="toc">
    <dt>
     <span class="section">
      <a href="se-csv-repair.html">
       18.4.1 Repairing and Checking CSV Tables
      </a>
     </span>
    </dt>
    <dt>
     <span class="section">
      <a href="se-csv-limitations.html">
       18.4.2 CSV Limitations
      </a>
     </span>
    </dt>
   </dl>
  </div>
  <a class="indexterm" name="idm46045147736576">
  </a>
  <a class="indexterm" name="idm46045147735504">
  </a>
  <p>
   The
   <code class="literal">
    CSV
   </code>
   storage engine stores data in text files
    using comma-separated values format.
  </p>
  <p>
   The
   <code class="literal">
    CSV
   </code>
   storage engine is always compiled into
    the MySQL server.
  </p>
  <p>
   To examine the source for the
   <code class="literal">
    CSV
   </code>
   engine, look in
    the
   <code class="filename">
    storage/csv
   </code>
   directory of a MySQL source
    distribution.
  </p>
  <p>
   When you create a
   <code class="literal">
    CSV
   </code>
   table, the server creates a
    plain text data file having a name that begins with the table name
    and has a
   <code class="filename">
    .CSV
   </code>
   extension. When you store data
    into the table, the storage engine saves it into the data file in
    comma-separated values format.
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa33649344"><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 prompt">mysql&gt;</span> <span class="token keyword">CREATE</span> <span class="token keyword">TABLE</span> test <span class="token punctuation">(</span>i <span class="token datatype">INT</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">,</span> c <span class="token datatype">CHAR</span><span class="token punctuation">(</span><span class="token number">10</span><span class="token punctuation">)</span> <span class="token operator">NOT</span> <span class="token boolean">NULL</span><span class="token punctuation">)</span>
<span class="token prompt">    -&gt;</span>     <span class="token keyword">ENGINE</span> <span class="token operator">=</span> CSV<span class="token punctuation">;</span>
<span class="token output">Query OK, 0 rows affected (0.06 sec)</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">INSERT</span> <span class="token keyword">INTO</span> test
<span class="token prompt">    -&gt;</span>     <span class="token keyword">VALUES</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span><span class="token string">'record one'</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token keyword">ROW</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">,</span><span class="token string">'record two'</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token output">Query OK, 2 rows affected (0.05 sec)</span>
<span class="token output">Records: 2  Duplicates: 0  Warnings: 0</span>

<span class="token prompt">mysql&gt;</span> <span class="token keyword">SELECT</span> <span class="token operator">*</span> <span class="token keyword">FROM</span> test<span class="token punctuation">;</span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> i <span class="token punctuation">|</span> c          <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output"><span class="token punctuation">|</span> 1 <span class="token punctuation">|</span> record one <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">|</span> 2 <span class="token punctuation">|</span> record two <span class="token punctuation">|</span></span>
<span class="token output"><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">-</span><span class="token punctuation">+</span></span>
<span class="token output">2 rows in set (0.00 sec)</span></code></pre>
  </div>
  <p>
   Creating a
   <code class="literal">
    CSV
   </code>
   table also creates a corresponding
    metafile that stores the state of the table and the number of rows
    that exist in the table. The name of this file is the same as the
    name of the table with the extension
   <code class="filename">
    CSM
   </code>
   .
  </p>
  <p>
   If you examine the
   <code class="filename">
    test.CSV
   </code>
   file in the
    database directory created by executing the preceding statements,
    its contents should look like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-none"><div class="docs-select-all right" id="sa79140145"><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">"1","record one"
"2","record two"</code></pre>
  </div>
  <p>
   This format can be read, and even written, by spreadsheet
    applications such as Microsoft Excel.
  </p>
 </div>
 <br/>
</div>
