snipt

Ctrl+h for KB shortcuts

Bash

Database dump and import from the commandline

1
2
3
4
5
#dump
mysqldump db_name --user=db_user -p > backup.sql

#import
mysql --user=username -p db_name < backup.sql
https://snipt.net/embed/55ee90c093ef42f638112fe20e7af750/
/raw/55ee90c093ef42f638112fe20e7af750/
55ee90c093ef42f638112fe20e7af750
bash
Bash
5
2019-07-11T09:47:26
True
False
False
/api/public/snipt/12915/
dump-a-database-from-the-commandline
<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="c1">#dump</span> </span><span id="L-2"><a name="L-2"></a>mysqldump db_name --user<span class="o">=</span>db_user -p &gt; backup.sql </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1">#import</span> </span><span id="L-5"><a name="L-5"></a>mysql --user<span class="o">=</span>username -p db_name &lt; backup.sql </span></pre></div> </td></tr></table>
backup, dump, mysql, mysqldump