Bug #108499 MySQL 8 client does not honour "-p" unless a password is included

Submitted: 15 Sep 2022 19:02 Modified: 15 Nov 2022 19:59
Reporter: Joe Creighton Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:8.0.30 OS:Linux (Generic)
Assigned to: CPU Architecture:x86

[15 Sep 2022 19:02] Joe Creighton
Description:
MySQL 8 client does not honour "-p" unless a password is included: it doesn't prompt for a password and throws an immediate error regardless of user/host options passed and correct user,host combinations in mysql.user table:

mysql -u user -h host -p
ERROR 1045 (28000): Access denied for user 'user'@'host' (using password: YES)

MySQL 8 client will connect as expected with:

mysql -u user -ppassword

but this is not viable.

MySQL 5.7 client honours "-p" when passed without a password: it prompts for a password, with or without "-u" and regardless of what user is defined in ~/.my.cnf or ~/.mylogin.cnf:

mysql -u user -p
Enter password: 

man page for both versions state that -p with no argument should prompt for a password.

How to repeat:
mysql -u user -p

Suggested fix:
This workaround reverts to expected behaviour:

mysql --no-defaults -u user -p
Enter password: 

but is not ideal.  Revert to old behaviour so this option is not needed?
[15 Sep 2022 19:05] Joe Creighton
Corrected Category
[14 Nov 2022 12:50] MySQL Verification Team
Hello Joe Creighton,

Thank you for the bug report.
I tried to reproduce your issue with MySQL server 8.0.31 through command-line but I am not seeing any issues at my end.

Regards,
Ashwini Patil
[15 Nov 2022 19:46] Joe Creighton
I see in the 8.0.31 release notes that this has been fixed:  Following a bug fix in MySQL 8.0.29, if the password was provided in an option file, the mysql client did not prompt for a password if the -p option was specified at login. The client now always prompts for a password when the -p option is specified and uses the specified password, even if an alternative was populated from an option file. (Bug #107205, Bug #34134984)
[15 Nov 2022 19:59] Joe Creighton
Although the previous bug was the reverse scenario, I'll be testing my scenario -- passing user and "-p" in order to connect as a different user and be prompted for credentials -- as soon as I can patch.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.