> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connecting to MySQL from the command line

> Connect to MySQL from the command line with this guide featuring step-by-step instructions, code snippets, and related resources.

This article describes how to connect to MySQL from the command line using the *mysql* program. You can use the *mysql* program as a quick and easy way to access your databases directly.

## Connecting to MySQL from the command line

To connect to MySQL from the command line, follow these steps:

1. Log in to your account [using SSH](/docs/using-ssh-secure-shell).

2. At the command line, type the following command, replacing ***username*** with your username:

   ```bash theme={null}
   mysql -u username -p
   ```

3. At the **Enter Password** prompt, type your password. When you type the correct password, the **mysql>** prompt appears.

4. To display a list of databases, type the following command at the **mysql>** prompt:

   ```bash theme={null}
   show databases;
   ```

   > 📘 Note
   >
   > Make sure you do not forget the semicolon at the end of the statement.

5. To access a specific database, type the following command at the **mysql>** prompt, replacing ***dbname*** with the name of the database that you want to access:

   ```bash theme={null}
   use dbname;
   ```

   > 📘 Note
   >
   > Make sure you do not forget the semicolon at the end of the statement.

6. After you access a database, you can run SQL queries, list tables, and so on. Additionally:

   * To view a list of MySQL commands, type `help` at the **mysql>** prompt.

   * To exit the *mysql* program, type `\q` at the **mysql>** prompt.

   > 👍 Tip
   >
   > When you run a command at the **mysql>** prompt, you may receive a warning message if MySQL encounters a problem. For example, you may run a query and receive a message that resembles the following:
   >
   > ```
   > Query OK, 0 rows affected, 1 warning (0.04 sec).
   > ```
   >
   > To view the complete warning message, type the following command:
   >
   > ```bash theme={null}
   > SHOW WARNINGS;
   > ```

## More information

For more information about the *mysql* command line program, please visit [http://dev.mysql.com/doc/refman/5.1/en/mysql.html](http://dev.mysql.com/doc/refman/5.1/en/mysql.html).

## Related articles

* [Connecting to PostgreSQL using psql](/docs/connect-to-postgresql-from-the-command-line)

* [Connecting to SQLite from the command line](/docs/connect-to-sqlite-from-the-command-line)

* [Connecting to MySQL using PHP](/docs/connect-to-mysql-using-php)

* [Connecting to MySQL using Python](/docs/connecting-to-mysql-using-python)

* [Connecting to MySQL using Microsoft.NET](/docs/connecting-to-mysql-using-microsoft-net)

* [Managing MySQL databases, users, and tables from the command line](/docs/managing-mysql-databases-and-users-from-the-command-line)
