<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h4 class="title">
      <a name="mysqldump-copying-to-other-server">
      </a>
      9.4.5.2 Copy a Database from one Server to Another
     </h4>
    </div>
   </div>
  </div>
  <p>
   On Server 1:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa32281046"><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">mysqldump</span> <span class="token property">--databases</span> db1 &gt; dump<span class="token punctuation">.</span>sql</code></pre>
  </div>
  <p>
   Copy the dump file from Server 1 to Server 2.
  </p>
  <p>
   On Server 2:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa68841935"><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>
   Use of
   <a class="link" href="mysqldump.html#option_mysqldump_databases">
    <code class="option">
     --databases
    </code>
   </a>
   with the
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   command line causes the dump file
          to include
   <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 that create the
          database if it does exist and make it the default database for
          the reloaded data.
  </p>
  <p>
   Alternatively, you can omit
   <a class="link" href="mysqldump.html#option_mysqldump_databases">
    <code class="option">
     --databases
    </code>
   </a>
   from the
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   command. Then you need to create
          the database on Server 2 (if necessary) and specify it as the
          default database when you reload the dump file.
  </p>
  <p>
   On Server 1:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa94456459"><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">mysqldump</span> db1 &gt; dump<span class="token punctuation">.</span>sql</code></pre>
  </div>
  <p>
   On Server 2:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa53504691"><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
<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>
   You can specify a different database name in this case, so
          omitting
   <a class="link" href="mysqldump.html#option_mysqldump_databases">
    <code class="option">
     --databases
    </code>
   </a>
   from
          the
   <a class="link" href="mysqldump.html" title="6.5.4 mysqldump — A Database Backup Program">
    <span class="command">
     <strong>
      mysqldump
     </strong>
    </span>
   </a>
   command enables you to dump
          data from one database and load it into another.
  </p>
 </div>
 <br/>
</div>
