Connecting to MySQL from the command line
To connect to MySQL from the command line, follow these steps:- Log in to your account using SSH.
-
At the command line, type the following command, replacing username with your username:
- At the Enter Password prompt, type your password. When you type the correct password, the mysql> prompt appears.
-
To display a list of databases, type the following command at the mysql> prompt:
📘 Note Make sure you do not forget the semicolon at the end of the statement.
-
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:
📘 Note Make sure you do not forget the semicolon at the end of the statement.
-
After you access a database, you can run SQL queries, list tables, and so on. Additionally:
-
To view a list of MySQL commands, type
helpat the mysql> prompt. -
To exit the mysql program, type
\qat 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:
To view the complete warning message, type the following command: -
To view a list of MySQL commands, type