Connecting to MySQL from the Command Line Interface

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

  • Log into your Server using SSH.
  • At the command line, type the following command, replacing USERNAME with your username:
    • mysql -u USERNAME -p
  • 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:
    • show databases;
  • To access a specific database, type the following command at the mysql> prompt, replacing DBNAME with the database that you want to access:
    • use DBNAME;
  • 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.