<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="use">
      </a>
      15.8.4 USE Statement
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045167844592">
  </a>
  <a class="indexterm" name="idm46045167843552">
  </a>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa45164723"><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 keyword">USE</span> <em class="replaceable">db_name</em></code></pre>
  </div>
  <p>
   The
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statement tells MySQL to
      use the named database as the default (current) database for
      subsequent statements. This statement requires some privilege for
      the database or some object within it.
  </p>
  <p>
   The named database remains the default until the end of the
      session or another
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statement is
      issued:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa50358340"><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 keyword">USE</span> db1<span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token function">COUNT</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token punctuation">)</span> <span class="token keyword">FROM</span> mytable<span class="token punctuation">;</span>   <span class="token comment" spellcheck="true"># selects from db1.mytable</span>
<span class="token keyword">USE</span> db2<span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> <span class="token function">COUNT</span><span class="token punctuation">(</span><span class="token operator">*</span><span class="token punctuation">)</span> <span class="token keyword">FROM</span> mytable<span class="token punctuation">;</span>   <span class="token comment" spellcheck="true"># selects from db2.mytable</span></code></pre>
  </div>
  <p>
   The database name must be specified on a single line. Newlines in
      database names are not supported.
  </p>
  <p>
   Making a particular database the default by means of the
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statement does not preclude
      accessing tables in other databases. The following example
      accesses the
   <code class="literal">
    author
   </code>
   table from the
   <code class="literal">
    db1
   </code>
   database and the
   <code class="literal">
    editor
   </code>
   table from the
   <code class="literal">
    db2
   </code>
   database:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa11425340"><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 keyword">USE</span> db1<span class="token punctuation">;</span>
<span class="token keyword">SELECT</span> author_name<span class="token punctuation">,</span>editor_name <span class="token keyword">FROM</span> author<span class="token punctuation">,</span>db2<span class="token punctuation">.</span>editor
  <span class="token keyword">WHERE</span> author<span class="token punctuation">.</span>editor_id <span class="token operator">=</span> db2<span class="token punctuation">.</span>editor<span class="token punctuation">.</span>editor_id<span class="token punctuation">;</span></code></pre>
  </div>
 </div>
 <br/>
</div>
