Home > Database > Mysql Tutorial > body text

MySQL option default values, option expectations, and = sign

WBOY
Release: 2023-09-15 19:09:02
forward
1068 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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.
Copy after login

We then execute the following command -

Query

mysql> SELECT CURRENT_USER();
Copy after login

Output

+----------------+
| CURRENT_USER() |
+----------------+
| jon@%          |
+----------------+
1 row in set (0.00 sec)
Copy after login

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
Copy after login

Output

mysql: option '--user' requires an argument
Copy after login

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
Copy after login

Output

ERROR 2005 (HY000): Unknown MySQL server host '--user' (1)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template