Knowledgebase Home / How to Connect to MySQL from the Command Line
// View Comments //

How to Connect to MySQL from the Command Line

MySQL is a database system that processes data using Structured Query Language. It’s one of the most widely used open-source database systems at the moment, which is frequently combined with PHP to build dynamic web pages. This article describes how to connect to MySQL from the command line using the MySQL program in cPanel accounts.

Quick steps:

  1. Log in to your cPanel account.
  2. Access your Terminal from the cPanel dashboard under the ADVANCED section
  3. Type the following command on the Terminal, replacing your username with your MySQL username:
    mysql -u username -p 
  4. Enter your password at the Enter Password screen, and the
    mysql> prompt appears.

How to connect to MySQL from the command line interface

Log in to your cPanel account and navigate to the Terminal section under the ADVANCED section.

Terminal option in cPanel

Type in the following command on the Terminal, replacing the username with your username

mysql -u username -p

MySQL prompt

Enter your MySQL password at the Enter Password screen and hit Enter. If you enter the proper password, the mysql> prompt appears.

MySQL prompts after login

Enter the following command at the mysql> prompt to show a list of databases:

show databases;

show tables command output in MySQL

Make sure you do not forget the semicolon at the end of the statement with every MySQL command.

To access a specific database, type the following command at the mysql> prompt

use dbname;

The dbname should be replaced with the actual name of the database you need to access:

use database command in MySQL

You can do much more SQL queries, and other operations after you access a database.

Conclusion:

Congratulations, you have now learned how to connect to MySQL from the command line interface.


If you have any web hosting questions please feel free to reach out to us. We're happy to help.
Shared Hosting | Reseller Hosting | Managed WordPress Hosting | Fully Managed VPS Hosting

Our Guiding Principles

  • Provide consistent, stable, and reliable web hosting services.
  • Ensure rapid ticket response and quick resolutions to issues.
  • Never saturate or over-provision servers to ensure stability and speed for our customers.
  • Use only high-quality enterprise-class hardware to ensure minimal downtime from hardware failures.
  • Provide clear pricing with no hidden fees or gotchas.
Subscribe to comment notifications
Notify of
guest
0 Comments
Inline Feedbacks
View all comments