Home > OS >  mysql password command line option --pasword="" fails but -p prompt succeeds?
mysql password command line option --pasword="" fails but -p prompt succeeds?

Time:12-11

Scratching my head on this one.

I can connect to mysql using the -p option for password authentication

kevzettler@kevs-mbp-3 radcade-wordpress % mysql -h localhost -P 3306 --protocol=tcp -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 21
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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> \q
Bye

However when I try using the extended -password option it consistently gets Access denied rejected.

kevzettler@kevs-mbp-3 radcade-wordpress % mysql -h localhost -P 3306 --protocol=tcp -u root -password='password'
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'172.24.0.1' (using password: YES)

Is there some hidden security option rejecting the commandline password?

CodePudding user response:

The long option must be prefixed with two dashes.

Like this:

--password='xyzzy'

Not like this:

-password='xyzzy'

With one option, it is literally the -p short option, followed by the password string assword=xyzzy. The short option has one dash prefix.

In MySQL, the short -p option requires no space between the option character and the password string. This is because -p followed by a space means to prompt for the password interactively.

  • Related