Program options specified on the command line follow these rules:命令行上指定的程序选项遵循以下规则:
Options are given after the command name.选项在命令名之后给出。
An option argument begins with one dash or two dashes, depending on whether it is a short form or long form of the option name. 选项参数以一个破折号或两个破折号开头,这取决于它是选项名称的短格式还是长格式。Many options have both short and long forms. 许多选项有短格式和长格式。For example, 例如,-?
and --help
are the short and long forms of the option that instructs a MySQL program to display its help message.-?
和--help
是指示MySQL程序显示其帮助消息的选项的长短形式。
Option names are case-sensitive. 选项名称区分大小写。-v
and -V
are both legal and have different meanings. -v
和-V
都是合法的,有不同的含义。(They are the corresponding short forms of the (它们是--verbose
and --version
options.)--verbose
和--version
选项的对应缩写形式。)
Some options take a value following the option name. 有些选项在选项名称后加上一个值。For example, 例如,-h localhost
or --host=localhost
indicate the MySQL server host to a client program. -h localhost
或--host=localhost
表示客户端程序的MySQL服务器主机。The option value tells the program the name of the host where the MySQL server is running.选项值告诉程序运行MySQL服务器的主机的名称。
For a long option that takes a value, separate the option name and the value by an 对于接受值的长选项,请使用=
sign. =
符号分隔选项名称和值。For a short option that takes a value, the option value can immediately follow the option letter, or there can be a space between: 对于接受值的短选项,选项值可以紧跟在选项字母后面,或者,两者之间可以有一个空格:-hlocalhost
and -h localhost
are equivalent. -hlocalhost
和-h localhost
是等价的。An exception to this rule is the option for specifying your MySQL password. 此规则的一个例外是指定MySQL密码的选项。This option can be given in long form as 该选项可以以--password=
or as pass_val
--password
. --password=
或pass_val
--password
的形式给出。In the latter case (with no password value given), the program interactively prompts you for the password. 在后一种情况下(没有给出密码值),程序会以交互方式提示您输入密码。The password option also may be given in short form as 密码选项也可以缩写为-p
or as pass_val
-p
. -p
或pass_val
-p
。However, for the short form, if the password value is given, it must follow the option letter with no intervening space: If a space follows the option letter, the program has no way to tell whether a following argument is supposed to be the password value or some other kind of argument. 但是,对于缩写形式,如果给定了密码值,则它必须在选项字母后面,并且没有中间空格:如果在选项字母后面有空格,则程序无法判断下面的参数应该是密码值还是其他类型的参数。Consequently, the following two commands have two completely different meanings:因此,以下两个命令具有两种完全不同的含义:
mysql -ptest mysql -p test
The first command instructs mysql to use a password value of 第一个命令指示mysql使用密码值test
, but specifies no default database. test
,但不指定默认数据库。The second instructs mysql to prompt for the password value and to use 第二个命令指示mysql提示输入密码值,并使用test
as the default database.test
作为默认数据库。
Within option names, dash (在选项名称中,破折号(-
) and underscore (_
) may be used interchangeably. -
)和下划线(_
)可以互换使用。For example, 例如,--skip-grant-tables
and --skip_grant_tables
are equivalent. --skip-grant-tables
和--skip_grant_tables
是等效的。(However, the leading dashes cannot be given as underscores.)(但是,前导破折号不能用下划线表示。)
The MySQL server has certain command options that may be specified only at startup, and a set of system variables, some of which may be set at startup, at runtime, or both. MySQL服务器具有某些仅在启动时指定的命令选项,以及一组系统变量,其中一些可以在启动时、运行时或两者同时设置。System variable names use underscores rather than dashes, and when referenced at runtime (for example, using 系统变量名使用下划线而不是破折号,在运行时引用时(例如,使用SET
or SELECT
statements), must be written using underscores:SET
或SELECT
语句),必须使用下划线写入:
SET GLOBAL general_log = ON; SELECT @@GLOBAL.general_log;
At server startup, the syntax for system variables is the same as for command options, so within variable names, dashes and underscores may be used interchangeably. 在服务器启动时,系统变量的语法与命令选项的语法相同,因此在变量名中,破折号和下划线可以互换使用。For example, 例如,--general_log=ON
and --general-log=ON
are equivalent. (This is also true for system variables set within option files.)--general_log=ON
和--general-log=ON
是等价的(在选项文件中设置的系统变量也是如此。)
For options that take a numeric value, the value can be given with a suffix of 对于采用数值的选项,该值可以用后缀K
, M
, or G
to indicate a multiplier of 1024, 10242 or 10243. K
、M
或G
表示1024、10242或10243的乘数。As of MySQL 8.0.14, a suffix can also be 从MySQL 8.0.14开始,后缀也可以是T
, P
, and E
to indicate a multiplier of 10244, 10245 or 10246. T
、P
和E
,以表示乘数为10244、10245或10246。Suffix letters can be uppercase or lowercase.后缀字母可以是大写或小写。
For example, the following command tells mysqladmin to ping the server 1024 times, sleeping 10 seconds between each ping:例如,以下命令告诉mysqladmin ping服务器1024次,每次ping之间休眠10秒:
mysqladmin --count=1K --sleep=10 ping
When specifying file names as option values, avoid the use of the 将文件名指定为选项值时,请避免使用~
shell metacharacter. ~
shell元字符。It might not be interpreted as you expect.它可能不会像您所期望的那样被解释。
Option values that contain spaces must be quoted when given on the command line. 在命令行中给出包含空格的选项值时,必须将其引用。For example, the 例如,--execute
(or -e
) option can be used with mysql to pass one or more semicolon-separated SQL statements to the server. --execute
(或-e
)选项可以与mysql一起使用,将一个或多个分号分隔的SQL语句传递给服务器。When this option is used, mysql executes the statements in the option value and exits. 使用此选项时,mysql执行选项值中的语句并退出。The statements must be enclosed by quotation marks. 这些陈述必须用引号括起来。For example:例如:
shell>mysql -u root -p -e "SELECT VERSION();SELECT NOW()"
Enter password:******
+------------+ | VERSION() | +------------+ | 8.0.19 | +------------+ +---------------------+ | NOW() | +---------------------+ | 2019-09-03 10:36:48 | +---------------------+ shell>
The long form (长格式(--execute
) is followed by an equal sign (=
).--execute
)后面跟一个等号(=
)。
To use quoted values within a statement, you must either escape the inner quotation marks, or use a different type of quotation marks within the statement from those used to quote the statement itself. 要在语句中使用引号,必须转义内部引号,或在语句中使用与用于引用语句本身的引号不同的引号。The capabilities of your command processor dictate your choices for whether you can use single or double quotation marks and the syntax for escaping quote characters. 命令处理器的功能决定了您可以选择使用单引号还是双引号,以及转义引号字符的语法。For example, if your command processor supports quoting with single or double quotation marks, you can use double quotation marks around the statement, and single quotation marks for any quoted values within the statement.例如,如果命令处理器支持使用单引号或双引号进行引用,则可以在语句周围使用双引号,并对语句中的任何引用值使用单引号。