Home » Access MySQL Database From Terminal

Directly access a MySQL database from the terminal. Connect with the given username, password, and host straight from the command line. Know more about the common errors when connecting to MySQL database.


  • MySQL
  • MySQL User with Password
  • MySQL Host

How To Connect To MySQL Database From The Command Line Terminal.

Step 1.

Open a shell and type the following.

mysql -uUSERNAME -p -hHOST


  • USERNAME is the user who has access to the database.
  • HOST is the host where the MySQL Database Server is hosted.

Step 2.

Enter password on prompt.


  • PASSWORD is the password of the user.


A successful login attempt will show a message similar to the following.

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 123
Server version: 5.5.35 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates.
All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or
its affiliates. Other names may be trademarks of their
respective owners.

Type 'help;' or '\h' for help. Type '\c' to clear
the current input statement.


A login attempt with a wrong password, or incorrect username will show a message like below.

ERROR 1045 (28000): Access denied for user 'USERNAME '@'localhost' (using password: YES)

A login attempt without putting the required password will have a similar message like below.

ERROR 1045 (28000): Access denied for user 'USERNAME '@'localhost' (using password: NO)


  • The HOST option is optional.
  • The default HOST is localhost
  • Including the PASSWORD value on the command line is a security risk, prompt MySQL to require the password.






Leave a Reply

Your email address will not be published. Required fields are marked *