Bug #109827 Mysqlsh doesn't read socket from cnf if I provide any arg on the command line
Submitted: 27 Jan 2023 21:45 Modified: 9 Jun 2023 15:34
Reporter: Doyle Briley Email Updates:
Status: Closed Impact on me:
None 
Category:Shell Upgrade Checker Severity:S3 (Non-critical)
Version:8.0.32 OS:Ubuntu (22.04.1)
Assigned to: CPU Architecture:x86 (2 cores Intel(R) Xeon(R) Platinum 8160 CPU @ 2.10GHz)
Tags: mysqlshell mysqlsh

[27 Jan 2023 21:45] Doyle Briley
Description:
If I run:
  mysqlsh -- util checkForServerUpgrade > mysqlUpgradeCheck.txt

It runs fine, but for some of the checks it tells me I need to provide the config file.  If I run:
  mysqlsh -- util checkForServerUpgrade --config-path=/etc/mysql/mysql.cnf > mysqlUpgradeCheck.txt

I get the following error:
  ERROR: Argument connectionData: Invalid connection options, expected either a URI or a Connection Options Dictionary

Now I am forced to provide the socket file location, which is already in the referenced config file.  So, now I have to run:
  mysqlsh -- util checkForServerUpgrade --socket=/var/run/mysqld/mysqld.sock --config-path=/etc/mysql/mysql.cnf > mysqlUpgradeCheck.txt

How to repeat:
Here is the information under [client] in /etc/mysql/mysql.cnf
  port=3306
  socket=/var/run/mysqld/mysqld.sock

I am currently on mysql server 5.7.40.

If other information is need, just let me know.
[9 Feb 2023 15:17] MySQL Verification Team
Hi,

Thank you for the report.
[4 May 2023 23:50] Juan Rene Ramirez Monarrez
Posted by developer:
 
Hi Bodgan

Thanks for submitting the bug report.

Short Explanation
-----------------
The problem is caused by a wrong logic on the parameter mapping when APIs are called using the CLI. When a parameter is not defined, the shell uses Null like value to fill the missing optional arguments and sice Null is not a valid value for connectionData, you get the described error.

Solution
--------
All the parameters that are optional have a valid default value defined, when the functions are called from CLI, such default value should be used for missing optional parameters instead of Null.

Long Story
----------
The actual signature of the checkForServerUpgrade is as follows:

    util.checkForServerUpgrade([connectionData][, options])

As you can see, both parameters are optional, in the case of the connection data, if nothing is provided, the utility will use the shell global session.

Following the different cases you describe:

Case 1: mysqlsh -- util checkForServerUpgrade

  - No connection data was specified and the utility executed OK. Since the utility executed OK that means there was a global session established, otherwise you would have seen the following error:
        ERROR: Please connect the shell to the MySQL server to be checked or specify the server URI as a parameter.

  - This means the session was established with data coming from some options file, you can verify this by executing:
        mysqlsh --print-defaults -- util checkForServerUpgrade

  - This would be the equivalent to starting the shell and executing: util.checkForServerUpgrade()
  - On this scenario the following happened:
    - Shell started
    - A global session was created using the connection data defined in some options file
    - The utility got called and used the global session to execute the checks since no connectionData was provided

Case 2: mysqlsh -- util checkForServerUpgrade --config-path=/etc/mysql/mysql.cnf

  - Here you are defined a value that gets associated to the second parameter of the utility: "options", since no explicit connection data was specified for the "connectionData" the CLI automatically filled connectionData with Null
  - This would be the equivalent to starting the shell and executing: util.checkForServerUpgrade(null, {configPath:'/etc/mysql/mysql.cnf'})
  - On this scenario the following happened:
    - Shell started
    - A global session was created using the connection data defined in some options file
    - The utility got called as described above and failed because Null is not a valid value for a connectionData parameter
  

Case 3: mysqlsh -- util checkForServerUpgrade --socket=/var/run/mysqld/mysqld.sock --config-path=/etc/mysql/mysql.cnf

    - Here you are defined a values for both parameters of the utility (--socket is a valid element on connectionData)
    - This would be the equivalent to starting the shell and executing: util.checkForServerUpgrade({socket:'/var/run/mysqld/mysqld.sock'}, {configPath:'/etc/mysql/mysql.cnf'})
    - On this scenario the following happened:
      - Shell started
      - A global session was created using the connection data defined in some options file
      - The utility got called and created yet a new session using the provided connectionData and used it to execute the checks.

With the correct fix, Case 2 should work just as Case 1 did, using the global session established with connection options from an options file.
[9 Jun 2023 15:34] Edward Gilmore
Posted by developer:
 
Added the following note to the MySQL Shell 8.0.34 and 8.1.0 release notes:
	
 MySQL Shell command line did not correctly handle missing optional arguments. 
 A NULL value was used instead of a valid value, resulting in an error.