Let us understand the default options, the options that expects values, and the ‘=’ sign in MySQL −
By convention, the long forms of options which assign a value are written using an equals (=) sign. It has been shown below −
mysql --host=tonfisk --user=jon
For options which require a value, i.e which doesn’t have a default value, the equal sign isn’t required. This means that the below command would be valid in such cases −
mysql --host tonfisk --user jon
In both the above cases, the mysql client tries to connect to a MySQL server that is running on the host named “tonfisk” with the help of an account whose user name is “jon”.
Because of this behavior, problems may occasionally show up when no value is provided for an option that expects a value to be provided.
Example
When a user connects to a MySQL server running on host tonfisk as user jon, the below command is run −
shell> mysql --host 85.224.35.45 --user jon
Output
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 8.0.25 Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
Then, we execute the below command −
Query
mysql> SELECT CURRENT_USER();
Output
+----------------+ | CURRENT_USER() | +----------------+ | jon@% | +----------------+ 1 row in set (0.00 sec)
When the required value is omitted for one of these options, it yields an error. The error may look like as shown below −
shell> mysql --host 85.224.35.45 –user
Output
mysql: option '--user' requires an argument
In the above case, mysql was unable to find a value after the --user option since nothing came after it on the command line. But if the user omits the value for an option which is not the last option to be used, a different error is obtained, which may not be expected by the user −
shell> mysql --host --user jon
Output
ERROR 2005 (HY000): Unknown MySQL server host '--user' (1)