There are several ways to specify options for MySQL programs:有几种方法可以指定MySQL程序的选项:
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.这对于希望程序每次运行时使用的选项来说是常见的。
List the options in environment variables (see Section 4.2.9, “Setting Environment Variables”). 列出环境变量中的选项(请参阅第4.2.9节,“设置环境变量”)。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 5.8.3, “Running Multiple MySQL Instances on Unix”, discusses one situation in which environment variables can be very helpful. 实际上,选项文件更常用于此目的,但第5.8.3节,“在Unix上运行多个MySQL实例”讨论了环境变量非常有用的一种情况。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.它描述了一种使用这些变量为服务器和客户端程序指定TCP/IP端口号和Unix套接字文件的简便技术。
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 以下命令使mysql连接到在localhost
:localhost
上运行的服务器:
mysql -h example.com -h localhost
There is one exception: For mysqld, the first instance of the 有一个例外:对于mysqld,--user
option is used as a security precaution, to prevent a user specified in an option file from being overridden on the command line.--user
选项的第一个实例用作安全预防措施,以防止在选项文件中指定的用户在命令行上被重写。
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:
mysql --column-names --skip-column-names
MySQL programs determine which options are given first by examining environment variables, then by processing option files, and then by checking the command line. MySQL程序首先通过检查环境变量,然后通过处理选项文件,然后通过检查命令行来确定给出了哪些选项。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.由于后面的选项优先于前面的选项,因此处理顺序意味着环境变量的优先级最低,命令行选项的优先级最高。
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.对于服务器,有一个例外:数据目录中的mysqld-auto.cnf选项文件是最后处理的,因此它甚至优先于命令行选项。
You can take advantage of the way that MySQL programs process options by specifying default option values for a program in an option file. 通过在选项文件中为程序指定默认选项值,可以利用MySQL程序处理选项的方式。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.这使您能够避免在每次运行程序时键入它们,同时允许您在必要时使用命令行选项覆盖默认值。