Bug #103383 setting password via non interactive session
Submitted: 20 Apr 2021 10:45 Modified: 20 Apr 2021 19:54
Reporter: Ankit Kapoor Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:8.0.23 OS:Any
Assigned to: CPU Architecture:Any
Tags: MariaDB, MySQL, percona mysql

[20 Apr 2021 10:45] Ankit Kapoor
Description:
I installed mysql post which I wanted to change the root user for very first time via non interactive method only i.e. not via entering into mysql (interactive mode).

For this mysql suggested me to use connect-expired-password and I did but even after using this with mysql , it throws error

[root@xyz ~]# /mysql-8.0.23-linux-glibc2.12-x86_64/bin/mysql -uroot -p';(d._-CZi8po' -connect-expired-password -e "alter user root@localhost identified by ';(d._-CZi8po';flush privileges;exit"
mysql: [Warning] Using a password on the command line interface can be insecure.
Please use --connect-expired-password option or invoke mysql in interactive mode.

With no clue of this I decide to pass "--" in the --connect-expired-password but then I saw below error related to the syntax :

[root@xyz ~]# /mysql-8.0.23-linux-glibc2.12-x86_64/bin/mysql -uroot -p';(d._-CZi8po' --connect-expired-password -e "alter user root@localhost identified by ';(d._-CZi8po';flush privileges;exit"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'exit' at line 1

After this I removed two "--" and again passed single "-" with connect-expired-password and this time it worked.

Hoping there must be some unknown problem at my end I tried reproducing this issue multiple times but every time I am facing this. I am seriously confused as what I am missing here. Request you to please guide.

How to repeat:
1. Install mysql .
2. When changing the root user for very first time do it via non-interactive mode and for this use connect-expired-password i.e. -connect-expired-password
3. mysql will still ask to use connect-expired-password to change the password.
4. pass "--" with connect-expired-password and it will throw syntax error.
5. again repeat the second step or same command and it will work.
[20 Apr 2021 10:49] Ankit Kapoor
Sorry I missed the last step when it worked. Hence I am pasting output of all the 3 steps:

[root@xyz ~]# /mysql-8.0.23-linux-glibc2.12-x86_64/bin/mysql -uroot -p';(d._-CZi8po' -connect-expired-password -e "alter user root@localhost identified by ';(d._-CZi8po';flush privileges;exit"
mysql: [Warning] Using a password on the command line interface can be insecure.
Please use --connect-expired-password option or invoke mysql in interactive mode.

[root@xyz ~]# /mysql-8.0.23-linux-glibc2.12-x86_64/bin/mysql -uroot -p';(d._-CZi8po' --connect-expired-password -e "alter user root@localhost identified by ';(d._-CZi8po';flush privileges;exit"
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'exit' at line 1

[root@xyz ~]# /mysql-8.0.23-linux-glibc2.12-x86_64/bin/mysql -uroot -p';(d._-CZi8po' -connect-expired-password -e "alter user root@localhost identified by ';(d._-CZi8po';flush privileges;exit"
mysql: [Warning] Using a password on the command line interface can be insecure.
[20 Apr 2021 12:57] MySQL Verification Team
Not a bug.  Just remove "exit" from the command you're running.  "exit" is not a valid SQL.
[20 Apr 2021 19:54] Ankit Kapoor
Thanks for your response. Yes I am agree that exit is not a part of SQL but even without removing "exit" clause, it worked.