Knowledge Base

How to use the command line to connect to MySQL

The mysql software may be used to connect to MySQL from the command line, as explained in this article. To quickly and easily access your databases directly, you can utilize the MySQL software.

Using the Command Line to Connect to MySQL

Use these procedures to establish a command-line connection to MySQL:

  • Use SSH to access your hostingws account.

  • Enter the following command at the command line, substituting your username for username:
mysql -u username -p```

- Enter your password at the Enter Password screen. The mysql> prompt shows up after you enter the right password.

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

show databases;```

  • list text hereEnter the following command at the mysql> prompt to access a particular database, substituting the database name for dbname:
use dbname;```

- list text hereSQL queries, list tables, and other operations can be performed after gaining access to a database. Furthermore:

  - Enter help at the mysql> prompt to see a list of MySQL commands.

  - Enter \q at the mysql> prompt to end the mysql program.

When you run a command at the mysql> prompt you may receive a warning message if
MySQL encounters a problem. For example, you may run a query and receive a message
that resembles the following:
Query 0K, e rows affected, 1 warning (0.04 sec).
To view the complete warning message, type the following command: ```


SHOW WARNINGS;```

### Additional Information

- The mysql command line application may be found at [http://dev.mysql.com/doc/refman/5.1/en/mysql.html](http://http://dev.mysql.com/doc/refman/5.1/en/mysql.html).
Please rate this article to help us improve our Knowledge Base.

0 0