Let’s understand the default options in MySQL, options that require a value, and the “=" symbol -
By convention, long-form options are assigned a value Write using the equal sign (=). As shown below -
mysql --host=tonfisk --user=jon
For options that require a value, i.e. options that have no default value, the equal sign is not required. This means that the following command will work in this case -
mysql --host tonfisk --user jon
In both the above cases, the mysql client will try to connect to the host named "tonfisk" with the help of an account with username "jon" The MySQL server that is running.
Because of this behavior, problems may sometimes occur when no value is provided for an option that requires a value to be provided.
Run the following command as user jon on host tonfisk when the user is connected to a running MySQL server -
shell> mysql --host 85.224.35.45 --user jon
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.
We then execute the following command -
mysql> SELECT CURRENT_USER();
+----------------+ | CURRENT_USER() | +----------------+ | jon@% | +----------------+ 1 row in set (0.00 sec)
When a required value for one of these options is omitted, an error is generated. The error may look like this -
shell> mysql --host 85.224.35.45 –user
mysql: option '--user' requires an argument
In the above case, mysql cannot find the value after the --user option because there is nothing after the option on the command line. However, if the user omits a value that is not the last option used, a different error will occur, which may be unexpected by the user -
shell> mysql --host --user jon
ERROR 2005 (HY000): Unknown MySQL server host '--user' (1)
The above is the detailed content of MySQL option default values, option expectations, and = sign. For more information, please follow other related articles on the PHP Chinese website!