2
votes

I can login to my mysql server using:

mysql -u root -p

Then I specify the password (i.e. PASS123) at the prompt. Login successful.

But when I try:

mysql -u root --password="PASS123"

i get:

mysql: [Warning] Using a password on the command line interface can be insecure. ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

My MySQL version: mysql Ver 14.14 Distrib 5.7.20, for Linux (x86_64) using EditLine wrapper

Maybe someone already had this problem? Is this a matter of some privileges that needs to be set additionally to allow login with password specified on command line?

2
My guess is that you have some characters in your password that are special to the shell, like " or ! or $. Anyway, you should learn how to use option files so you don't have to put passwords on the command-line at all. dev.mysql.com/doc/refman/8.0/en/option-files.html - Bill Karwin
Thanks for pointing out the special characters. I had the $ sign in the password. Changed that. Now it doesn't contain the $ and works well. This is very strange because i used quotations marks when specifying the password in command line and thought that this solves the special characters problem :) - przemaz
as @BillKarwin posted, the $ sign removed from password solved the problem. But this is rather workaround than solution. How to pass password as a command line parameter event if it contains the special characters (currently, by default needed by password policy)? - przemaz
Use single-quotes instead of double-quotes around your password on the command line to suppress shell interpretation of some kinds of metacharacters. But really, use option files. You shouldn't put passwords on the command-line. - Bill Karwin

2 Answers

1
votes

as @BillKarwin posted, the $ sign removed from password solved the problem.

0
votes

Best way to avoid such issue is using `` to enclose the password.

Option1:

mysql -h localhost -u dbuser --password='password@$here'

Option2:

mysql -h localhost -u dbuser -p'password@$here'

Note: Since many usually mistake this punctuation mark, I have added a picture of a key board to be clear.

Where to find the key