Mar 27, 2011

f Comment

How to Get Prompted To Enter MySQL Password While Connecting to MySQL Server?

AmazonI am running a MySQL command to connect to a MySQL database. What MySQL command would make MySQL prompt me to enter the user's password so that the password is not displayed on the screen?

The MySQL command to connect to a MySQL server is simple. You can use '-p' flag followed by the password like the following (assuming user is root and password is MyPassWord and you want to connect to localhost):

mysql -uroot -pMyPassWord
Let's say you'd like to enter the password passively, meaning you'd like to get prompted to enter the password and while doing so the password is NOT shown on the screen. The following is a failed attempt:

$ mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

This would work if 'root' does NOT have a password. This is not true because root does have a password. The correct command is the following:

$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 808754
Server version: 5.0.67-0ubuntu6 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


That's it! Any questions?
Please leave a comment here!
One Minute Information - by Michael Wen
ADVERTISING WITH US - Direct your advertising requests to Michael