How to connect to MySQL from the command line

This article will show you how to use the mysql program to connect to MySQL from the command line. You can use the mysql program to quickly and easily access your databases.

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

  1. Log in to your Hostginger Hosting account using SSH.
  2. At the command line, type the following command, replacing username with your username:
    mysql -u username -p
  3. At the Enter Password prompt, type your password. When you type the correct password, the mysql> prompt appears.
  4. To display a list of databases, type the following command at the mysql> prompt:

    show databases;
  5. 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:

    use dbname;
  6. After you access a database, you can run SQL queries, list tables, and so on. 

    • To view a list of commands, type help at the mysql> prompt.
    • To exit the mysql program, type \q at the mysql> prompt
     
Was this answer helpful?

Related Articles

How to connect to MySQL using Node.js

This article demonstrates how to connect to a MySQL database using Node.js. Connecting to MySQL...

How to connect to MySQL using Perl

This article describes two methods for connecting to a MySQL database using Perl: DBI...

How to connect to MySQL using PHP

This article describes several methods to connect to a MySQL database using PHP: MySQL...

How to connect to MySQL using Python

Python provides several ways to connect to a MySQL database and process data. This article...

How to convert a MySQL database to UTF-8 encoding

This article explains how to convert the character set of a MySQL database to UTF-8 encoding...