- 6.2.2.1 在命令行上使用选项6.2.2.1 Using Options on the Command Line
- 6.2.2.2 使用选项文件6.2.2.2 Using Option Files
- 6.2.2.3 影响选项文件处理的命令行选项6.2.2.3 Command-Line Options that Affect Option-File Handling
- 6.2.2.4 程序选项修饰符6.2.2.4 Program Option Modifiers
- 6.2.2.5 使用选项设置程序变量6.2.2.5 Using Options to Set Program Variables
- 6.2.2.6 选项默认值、期望值的选项以及 = 符号6.2.2.6 Option Defaults, Options Expecting Values, and the = Sign
有几种方法可以为 MySQL 程序指定选项:There are several ways to specify options for MySQL programs:
在程序名称之后的命令行上列出选项。这对于适用于程序特定调用的选项很常见。List the options on the command line following the program name. This is common for options that apply to a specific invocation of the program.
在程序启动时读取的选项文件中列出选项。这对于您希望程序每次运行时使用的选项很常见。List the options in an option file that the program reads when it starts. This is common for options that you want the program to use each time it runs.
在环境变量中列出选项(参见第 6.2.9 节,“设置环境变量”)。这种方法对于每次程序运行时都想应用的选项非常有用。在实际中,选项文件更常用于此目的,但第 7.8.3 节,“在 Unix 上运行多个 MySQL 实例”,讨论了一种环境变量非常有用的情况。它描述了一种利用这些变量来指定服务器和客户端程序的 TCP/IP 端口号及 Unix 套接字文件的方便技巧。List the options in environment variables (see Section 6.2.9, “Setting Environment Variables”). This method is useful for options that you want to apply each time the program runs. In practice, option files are used more commonly for this purpose, but Section 7.8.3, “Running Multiple MySQL Instances on Unix”, discusses one situation in which environment variables can be very helpful. It describes a handy technique that uses such variables to specify the TCP/IP port number and Unix socket file for the server and for client programs.
选项按顺序处理,因此如果某个选项被多次指定,最后一次出现的将优先。以下命令使 mysql 连接到运行在 localhost 的服务器:Options are processed in order, so if an option is specified
multiple times, the last occurrence takes precedence. The
following command causes mysql to connect to
the server running on localhost:
mysql -h example.com -h localhost
有一个例外:对于 mysqld,会使用 第一次 出现的 --user 选项,作为安全预防措施,以防在选项文件中指定的用户在命令行上被覆盖。There is one exception: For mysqld, the
first instance of the
--user option is used as a security
precaution, to prevent a user specified in an option file from
being overridden on the command line.
如果给出了冲突或相关的选项,以后的选项优先于前面的选项。以下命令以“无列名”模式运行mysql:If conflicting or related options are given, later options take precedence over earlier options. The following command runs mysql in “no column names” mode:
mysql --column-names --skip-column-names
MySQL 程序通过检查环境变量、处理选项文件,然后检查命令行来确定哪些选项优先给出。由于后面的选项优先于前面的选项,因此处理顺序意味着环境变量的优先级最低,而命令行选项的优先级最高。MySQL programs determine which options are given first by examining environment variables, then by processing option files, and then by checking the command line. Because later options take precedence over earlier ones, the processing order means that environment variables have the lowest precedence and command-line options the highest.
对于服务器,有一个例外:数据目录中的 mysqld-auto.cnf 选项文件最后被处理,因此它甚至优先于命令行选项。For the server, one exception applies: The mysqld-auto.cnf option file in the data directory is processed last, so it takes precedence even over command-line options.
你可以通过在选项文件中为程序指定默认选项值来利用 MySQL 程序处理选项的方式。这使你能够在每次运行程序时避免输入这些选项,同时如果有必要,也可以通过使用命令行选项来覆盖默认值。You can take advantage of the way that MySQL programs process options by specifying default option values for a program in an option file. That enables you to avoid typing them each time you run the program while enabling you to override the defaults if necessary by using command-line options.