How to Connect to the MySQL using the Command Line

March 30, 2022 / MySQL

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:

  1. Log in to your hosting account via SSH. (SSH is a command-line interface that allows you to access your hosting account.)
  2. Type the command at the command prompt, substituting username with your username:
    mysql -u username -p
  3. 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;
  4. 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;
  5. You can perform SQL queries, list tables, and so on after you’ve accessed a database. Furthermore:
    1. Type help at the mysql> prompt to see a list of MySQL commands.
    2. Type q at the mysql> prompt to exit the programme.

This way you can easily connect to your database using the command line,

Dominos Search