<div id="docs-body">
 <div class="section">
  <div class="titlepage">
   <div>
    <div>
     <h2 class="title">
      <a name="connecting-disconnecting">
      </a>
      5.1 Connecting to and Disconnecting from the Server
     </h2>
    </div>
   </div>
  </div>
  <a class="indexterm" name="idm46045325684192">
  </a>
  <a class="indexterm" name="idm46045325682704">
  </a>
  <a class="indexterm" name="idm46045325681216">
  </a>
  <a class="indexterm" name="idm46045325679728">
  </a>
  <p>
   To connect to the server, you usually need to provide a MySQL user
      name 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>
   and, most likely, a
      password. If the server runs on a machine other than the one where
      you log in, you must also specify a host name. Contact your
      administrator to find out what connection parameters you should
      use to connect (that is, what host, user name, and password to
      use). Once you know the proper parameters, you should be able to
      connect like this:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa83410438"><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>
Enter password<span class="token punctuation">:</span> ********</code></pre>
  </div>
  <p>
   <em class="replaceable">
    <code>
     host
    </code>
   </em>
   and
   <em class="replaceable">
    <code>
     user
    </code>
   </em>
   represent the host name where your
      MySQL server is running and the user name of your MySQL account.
      Substitute appropriate values for your setup. The
   <code class="literal">
    ********
   </code>
   represents your password; enter it
      when
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   displays the
   <code class="literal">
    Enter
      password:
   </code>
   prompt.
  </p>
  <p>
   If that works, you should see some introductory information
      followed by a
   <code class="literal">
    mysql&gt;
   </code>
   prompt:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-terminal"><div class="docs-select-all right" id="sa46609857"><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>
Enter password<span class="token punctuation">:</span> ********
Welcome to the MySQL monitor<span class="token punctuation">.</span>  Commands end with <span class="token punctuation">;</span> or \g<span class="token punctuation">.</span>
Your MySQL connection id is 25338 to server version<span class="token punctuation">:</span> 8<span class="token punctuation">.</span>4<span class="token punctuation">.</span>3-standard

Type <span class="token atrule">'help;'</span> or <span class="token atrule">'\h'</span> for help<span class="token punctuation">.</span> Type <span class="token atrule">'\c'</span> to clear the buffer<span class="token punctuation">.</span>

<span class="token prompt">mysql&gt;</span></code></pre>
  </div>
  <p>
   The
   <code class="literal">
    mysql&gt;
   </code>
   prompt tells you that
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   is ready for you to enter SQL statements.
  </p>
  <p>
   If you are logging in on the same machine that MySQL is running
      on, you can omit the host, and simply use the following:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa58352605"><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">-u</span> <em class="replaceable">user</em> <span class="token property">-p</span></code></pre>
  </div>
  <p>
   If, when you attempt to log in, you get an error message such as
   <span class="errortext">
    ERROR 2002 (HY000): Can't connect to local MySQL server
      through socket '/tmp/mysql.sock' (2)
   </span>
   , it means that
      the MySQL server daemon (Unix) or service (Windows) is not
      running. Consult the administrator or see the section of
   <a class="xref" href="installing.html" title="Chapter 2 Installing MySQL">
    Chapter 2,
    <i>
     Installing MySQL
    </i>
   </a>
   that is appropriate to your operating
      system.
  </p>
  <p>
   For help with other problems often encountered when trying to log
      in, see
   <a class="xref" href="common-errors.html" title="B.3.2 Common Errors When Using MySQL Programs">
    Section B.3.2, “Common Errors When Using MySQL Programs”
   </a>
   .
  </p>
  <p>
   Some MySQL installations permit users to connect as the anonymous
      (unnamed) user to the server running on the local host. If this is
      the case on your machine, you should be able to connect to that
      server by invoking
   <a class="link" href="mysql.html" title="6.5.1 mysql — The MySQL Command-Line Client">
    <span class="command">
     <strong>
      mysql
     </strong>
    </span>
   </a>
   without any options:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting one-line language-terminal"><div class="docs-select-all right" id="sa74607461"><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></code></pre>
  </div>
  <p>
   After you have connected successfully, you can disconnect any time
      by typing
   <code class="literal">
    QUIT
   </code>
   (or
   <code class="literal">
    \q
   </code>
   ) at
      the
   <code class="literal">
    mysql&gt;
   </code>
   prompt:
  </p>
  <div class="copytoclipboard-wrapper">
   <pre class="programlisting language-sql"><div class="docs-select-all right" id="sa35101348"><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> QUIT
Bye</code></pre>
  </div>
  <p>
   On Unix, you can also disconnect by pressing Control+D.
  </p>
  <p>
   Most examples in the following sections assume that you are
      connected to the server. They indicate this by the
   <code class="literal">
    mysql&gt;
   </code>
   prompt.
  </p>
 </div>
 <br/>
</div>
