Home  >  Article  >  Database  >  MySQL option default values, option expectations, and = sign

MySQL option default values, option expectations, and = sign

WBOY
WBOYforward
2023-09-15 19:09:021039browse

MySQL 选项默认值、选项期望值和 = 符号

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.

Example

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

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.

We then execute the following command -

Query

mysql> SELECT CURRENT_USER();

Output

+----------------+
| 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

Output

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

Output

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete