<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="reloading-sql-format-dumps">
      </a>
      9.4.2 Reloading SQL-Format Backups
     </h3>
    </div>
   </div>
  </div>
  <p>
   To reload a dump file written by
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   that consists of SQL statements, use it as input to the
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   client. If the dump file was created by
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   with the
   <a class="link" href="mysqldump.html#option_mysqldump_all-databases">
    <code class="option">
     --all-databases
    </code>
   </a>
   or
   <a class="link" href="mysqldump.html#option_mysqldump_databases">
    <code class="option">
     --databases
    </code>
   </a>
   option, it
        contains
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE DATABASE
    </code>
   </a>
   and
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statements and it is not
        necessary to specify a default database into which to load the
        data:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa79967883"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> &lt; dump<span class="token punctuation">.</span>sql</code></pre>
  </div>
  <p>
   Alternatively, from within
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   , use a
   <code class="literal">
    source
   </code>
   command:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa27478779"><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">source</span> dump<span class="token punctuation">.</span><span class="token keyword">sql</span></code></pre>
  </div>
  <p>
   If the file is a single-database dump not containing
   <a class="link" href="create-database.html" title="15.1.12 CREATE DATABASE Statement">
    <code class="literal">
     CREATE DATABASE
    </code>
   </a>
   and
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statements, create the
        database first (if necessary):
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa56833603"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysqladmin</span> create db1</code></pre>
  </div>
  <p>
   Then specify the database name when you load the dump file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa28300508"><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-terminal"><span class="token prompt">$&gt; </span><span class="token command">mysql</span> db1 &lt; dump<span class="token punctuation">.</span>sql</code></pre>
  </div>
  <p>
   Alternatively, from within
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   , create the
        database, select it as the default database, and load the dump
        file:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa24095904"><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">DATABASE</span> <span class="token keyword">IF</span> <span class="token operator">NOT</span> <span class="token keyword">EXISTS</span> db1<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">USE</span> db1<span class="token punctuation">;</span>
<span class="token prompt">mysql&gt;</span> <span class="token keyword">source</span> dump<span class="token punctuation">.</span><span class="token keyword">sql</span></code></pre>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    For Windows PowerShell users: Because the "&lt;" character is
          reserved for future use in PowerShell, an alternative approach
          is required, such as using quotes
    <code class="literal">
     cmd.exe /c "mysql
          &lt; dump.sql"
    </code>
    .
   </p>
  </div>
 </div>
 <br/>
</div>
