snipt

Ctrl+h for KB shortcuts

MySQL

mysql dump results to csv

1
2
3
4
5
6
select my_columns 
into outfile '/tmp/results.csv'
fields terminated by ',' optionally enclosed by '"'
escaped by '\\'
lines terminated by '\n'
from my_table;
https://snipt.net/embed/f737d5523136f89ce329ce2eb3b4b293/
/raw/f737d5523136f89ce329ce2eb3b4b293/
f737d5523136f89ce329ce2eb3b4b293
mysql
MySQL
6
2019-07-19T21:13:36
True
False
False
/api/public/snipt/3279/
mysql-dump-results-to-csv
<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> <a href="#L-6">6</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">select</span> <span class="n">my_columns</span> </span><span id="L-2"><a name="L-2"></a><span class="k">into</span> <span class="k">outfile</span> <span class="s1">&#39;/tmp/results.csv&#39;</span> </span><span id="L-3"><a name="L-3"></a><span class="n">fields</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;,&#39;</span> <span class="k">optionally</span> <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">escaped</span> <span class="k">by</span> <span class="s1">&#39;\\&#39;</span> </span><span id="L-5"><a name="L-5"></a><span class="k">lines</span> <span class="k">terminated</span> <span class="k">by</span> <span class="s1">&#39;\n&#39;</span> </span><span id="L-6"><a name="L-6"></a><span class="k">from</span> <span class="n">my_table</span><span class="p">;</span> </span></pre></div> </td></tr></table>
csv, mysql