<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h3 class="title">
      <a name="creating-database">
      </a>
      5.3.1 Creating and Selecting a Database
     </h3>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045325483680">
  </a>
  <a class="indexterm" name="idm46045325482224">
  </a>
  <p>
   If the administrator creates your database for you when setting
        up your permissions, you can begin using it. Otherwise, you need
        to create it yourself:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-sql"><div class="docs-select-all right" id="sa56031372"><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> menagerie<span class="token punctuation">;</span></code></pre>
  </div>
  <p>
   Under Unix, database names are case-sensitive (unlike SQL
        keywords), so you must always refer to your database as
   <code class="literal">
    menagerie
   </code>
   , not as
   <code class="literal">
    Menagerie
   </code>
   ,
   <code class="literal">
    MENAGERIE
   </code>
   , or
        some other variant. This is also true for table names. (Under
        Windows, this restriction does not apply, although you must
        refer to databases and tables using the same lettercase
        throughout a given query. However, for a variety of reasons, the
        recommended best practice is always to use the same lettercase
        that was used when the database was created.)
  </p>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    If you get an error such as
    <span class="errortext">
     ERROR 1044 (42000):
          Access denied for user 'micah'@'localhost' to database
          'menagerie'
    </span>
    when attempting to create a database,
          this means that your user account does not have the necessary
          privileges to do so. Discuss this with the administrator or
          see
    <a class="xref" href="access-control.html" title="8.2 Access Control and Account Management">
     Section 8.2, “Access Control and Account Management”
    </a>
    .
   </p>
  </div>
  <p>
   Creating a database does not select it for use; you must do that
        explicitly. To make
   <code class="literal">
    menagerie
   </code>
   the current
        database, use this statement:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa34242085"><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">USE</span> menagerie
<span class="token keyword">Database</span> <span class="token keyword">changed</span></code></pre>
  </div>
  <p>
   Your database needs to be created only once, but you must select
        it for use each time you begin a
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   session. You can do this by issuing a
   <a class="link" href="use.html" title="15.8.4 USE Statement">
    <code class="literal">
     USE
    </code>
   </a>
   statement as shown in the
        example. Alternatively, you can select the database on the
        command line when you invoke
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   . Just
        specify its name after any connection parameters that you might
        need to provide. For example:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa98289492"><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> <span class="token property">-h</span> <em class="replaceable">host</em> <span class="token property">-u</span> <em class="replaceable">user</em> <span class="token property">-p</span> menagerie
Enter password<span class="token punctuation">:</span> ********</code></pre>
  </div>
  <div class="important" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Important
   </div>
   <p>
    <code class="literal">
     menagerie
    </code>
    in the command just shown is
    <span class="bold">
     <strong>
      not
     </strong>
    </span>
    your password. If you
          want to supply your password on the command line after the
    <code class="literal">
     -p
    </code>
    option, you must do so with no
          intervening space (for example, as
    <code class="literal">
     -p
     <em class="replaceable">
      <code>
       password
      </code>
     </em>
    </code>
    , not
          as
    <code class="literal">
     -p
     <em class="replaceable">
      <code>
       password
      </code>
     </em>
    </code>
    ).
          However, putting your password on the command line is not
          recommended, because doing so exposes it to snooping by other
          users logged in on your machine.
   </p>
  </div>
  <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
   <div class="admon-title">
    Note
   </div>
   <p>
    You can see at any time which database is currently selected
          using
    <a class="link" href="select.html" title="15.2.13 SELECT Statement">
     <code class="literal">
      SELECT
     </code>
    </a>
    <a class="link" href="information-functions.html#function_database">
     <code class="literal">
      DATABASE()
     </code>
    </a>
    .
   </p>
  </div>
 </div>
 <br/>
</div>
