snipt

Ctrl+h for KB shortcuts

MySQL

Import Excel CSV into mysql table

1
2
3
4
5
LOAD DATA LOCAL INFILE 'file.cvs' INTO TABLE tablename
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
(field1, field2, field3)
https://snipt.net/embed/b45c79fed7778c5162ab2733e55610f7/
/raw/b45c79fed7778c5162ab2733e55610f7/
b45c79fed7778c5162ab2733e55610f7
mysql
MySQL
6
2019-06-10T08:03:22
True
False
False
/api/public/snipt/4923/
import-excel-csv-into-mysql-table
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="k">LOAD</span> <span class="n">DATA</span> <span class="n">LOCAL</span> <span class="k">INFILE</span> <span class="s1">&#39;file.cvs&#39;</span> <span class="k">INTO</span> <span class="k">TABLE</span> <span class="n">tablename</span> </span><span id="L-2"><a name="L-2"></a><span class="n">FIELDS</span> <span class="k">TERMINATED</span> <span class="k">BY</span> <span class="s1">&#39;,&#39;</span> </span><span id="L-3"><a name="L-3"></a><span class="k">ENCLOSED</span> <span class="k">BY</span> <span class="s1">&#39;&quot;&#39;</span> </span><span id="L-4"><a name="L-4"></a><span class="k">LINES</span> <span class="k">TERMINATED</span> <span class="k">BY</span> <span class="s1">&#39;\r\n&#39;</span> </span><span id="L-5"><a name="L-5"></a><span class="p">(</span><span class="n">field1</span><span class="p">,</span> <span class="n">field2</span><span class="p">,</span> <span class="n">field3</span><span class="p">)</span> </span></pre></div> </td></tr></table>
csv, excel, mysql