This guide is going to help you in knowing how to connect to MySQL using a command line.
Steps to Connect to MySQL from the command line:
- Log in to your hosting account via SSH. (SSH is a command-line interface that allows you to access your hosting account.)
- Type the command at the command prompt, substituting username with your username:
mysql -u username -p - Enter your password at the Enter Password screen. The mysql> prompt occurs when you type the right password.
To display a list of databases, type the following command at the mysql> prompt
(Don’t forget to include the semicolon at the end of the statement.)
show databases; - At the mysql> prompt, type the following command, substituting dbname with the name of the database you want to access:
(Don’t forget to include the semicolon at the end of the statement.)
use dbname; - You can perform SQL queries, list tables, and so on after you’ve accessed a database. Furthermore:
- Type help at the mysql> prompt to see a list of MySQL commands.
- Type q at the mysql> prompt to exit the programme.
This way you can easily connect to your database using the command line,