Bug 2162091

Summary: mysql client not asking password when using "-p" option
Product: Red Hat Enterprise Linux 8 Reporter: Shreyas Mahangade <smahanga>
Component: mysqlAssignee: Michal Schorm <mschorm>
Status: CLOSED CURRENTRELEASE QA Contact: Jakub Heger <jheger>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.7CC: databases-maint, ljavorsk
Target Milestone: rcKeywords: Rebase, Triaged, ZStream
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard: Fixed by upstream in 8.0.31
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 2177735 (view as bug list) Environment:
Last Closed: 2023-05-22 12:28:00 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 2177735    

Description Shreyas Mahangade 2023-01-18 18:38:29 UTC
Description of problem:

mysql client is not enforcing enter password when using -p option.

Version-Release number of selected component (if applicable):

MySQL 8.0.29+

How reproducible:

Always

Steps to Reproduce:
1. Create a user in mysql

~~~
mysql> CREATE USER 'test'@'localhost' IDENTIFIED BY 'test';
~~~

2. Create a ~/.my.ini file for autologin

~~~
[root@rhel8localhost ~]# cat > ~/.my.cnf
[client]
user=test
password=test
~~~

3. Try to login with "-p". Mysql will not prompt for password even for different -u <users>

~~~
[root@rhel8localhost ~]# mysql -h localhost -u test -p 
[...]
mysql> quit
#Now changing user to root
[root@rhel8localhost ~]# mysql -h localhost -u root -p 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
~~~

4. Remove ~/.my.ini and now it asks for password:

~~~
[root@rhel8localhost ~]# echo "" > ~/.my.cnf 
[root@rhel8localhost ~]# cat ~/.my.cnf 
[root@rhel8localhost ~]# mysql -h localhost -u test -p
Enter password: 
[root@rhel8localhost ~]# mysql -h localhost -u root -p 
Enter password:
~~~

Actual results:

mysql client did not asked for password upon using -p

Expected results:
mysql should enforce entering password when using -p option

Additional info:

As per upstream I can see this issue is fixed here in 8.0.31 (Bug #107205, Bug #34134984):

https://downloads.mysql.com/docs/mysql-8.0-relnotes-en.pdf

• 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)