Connecting and Disconnecting from the MySQL Server

MySQL is an interactive program that allows you to connect to a MySQL server, run queries, and view the results. To connect to the server, you'll need to provide a MySQL user name when you invoke mysql and a password.

You should be able to connect like this:

shell> mysql -p
Enter password: ********

Note:If the server runs on a machine other than the one where you log in, you'll also need to specify a hostname.

shell> mysql -h host -u user -p
Enter password: ********

The ******** represents your password; enter it when mysql displays the Enter password: prompt.

If that works, you should see some introductory information followed by a mysql> prompt:

shell> mysql -h host -u user -p
Enter password: ********
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6 to server version: x.xx.xx
Type 'help;'  or '\h' for help. Type '\c\ to clear the buffer
mysql>

The prompt tells you that mysql is ready for you to enter commands.

After you have connected successfully, you can disconnect any time by typing QUIT at the mysql> prompt:

mysql> QUIT
Bye

You can also disconnect by pressing Control-D.

Back