Access a MySQL database from the terminal

November 10, 2013 | Last tested: May 2015 | 673 views | Comments

Directly access a MySQL database from the terminal.

For example.

A MySQL user should have been created, with a privilege already granted.

mysql -uUSERNAME -pPASSWORD

Where:

  1. USERNAME = the user who has access to the database.
  2. PASSWORD = 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.

mysql>

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 a required password will have a similar message like below.

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