4.6.7 mysql_config_editor — MySQL Configuration Utility配置实用程序

The mysql_config_editor utility enables you to store authentication credentials in an obfuscated login path file named .mylogin.cnf. mysql_config_editor实用程序使您能够将身份验证凭据存储在名为.mylogin.cnf的混淆登录路径文件中。The file location is the %APPDATA%\MySQL directory on Windows and the current user's home directory on non-Windows systems. 文件位置在Windows上为%APPDATA%\MySQL目录,在非Windows系统上为当前用户的主目录。The file can be read later by MySQL client programs to obtain authentication credentials for connecting to MySQL Server.MySQL客户端程序稍后可以读取该文件,以获取连接到MySQL服务器的身份验证凭据。

The unobfuscated format of the .mylogin.cnf login path file consists of option groups, similar to other option files. .mylogin.cnf登录路径文件的不复杂格式由选项组组成,类似于其他选项文件。Each option group in .mylogin.cnf is called a login path, which is a group that permits only certain options: host, user, password, port and socket. .mylogin.cnf中的每个选项组都称为“登录路径”,这是一个只允许某些选项的组:hostuserpasswordportsocketThink of a login path option group as a set of options that specify which MySQL server to connect to and which account to authenticate as. Here is an unobfuscated example:将登录路径选项组视为一组选项,指定要连接到哪个MySQL服务器以及要作为哪个帐户进行身份验证。以下是一个不复杂的示例:

[client]
user = mydefaultname
password = mydefaultpass
host = 127.0.0.1
[mypath]
user = myothername
password = myotherpass
host = localhost

When you invoke a client program to connect to the server, the client uses .mylogin.cnf in conjunction with other option files. Its precedence is higher than other option files, but less than options specified explicitly on the client command line. 当您调用客户端程序连接到服务器时,客户端将.mylogin.cnf与其他选项文件结合使用。它的优先级高于其他选项文件,但低于在客户端命令行上明确指定的选项。For information about the order in which option files are used, see Section 4.2.2.2, “Using Option Files”.有关选项文件使用顺序的信息,请参阅第4.2.2.2节,“使用选项文件”

To specify an alternate login path file name, set the MYSQL_TEST_LOGIN_FILE environment variable. 要指定备用登录路径文件名,请设置MYSQL_TEST_LOGIN_FILE环境变量。This variable is recognized by mysql_config_editor, by standard MySQL clients (mysql, mysqladmin, and so forth), and by the mysql-test-run.pl testing utility.此变量由mysql_config_editor、标准mysql客户端(mysqlmysqladmin等)和mysql-test-run.pl测试实用程序识别。

Programs use groups in the login path file as follows:程序在登录路径文件中使用组,如下所示:

mysql_config_editor obfuscates the .mylogin.cnf file so it cannot be read as cleartext, and its contents when unobfuscated by client programs are used only in memory. mysql_config_editor会混淆.mylogin.cnf文件,使其无法作为明文读取,并且当客户端程序未混淆时,其内容仅在内存中使用。In this way, passwords can be stored in a file in non-cleartext format and used later without ever needing to be exposed on the command line or in an environment variable. 通过这种方式,密码可以以非明文格式存储在文件中,并在以后使用,而无需在命令行或环境变量中公开。mysql_config_editor provides a print command for displaying the login path file contents, but even in this case, password values are masked so as never to appear in a way that other users can see them.mysql_config_editor提供了一个打印命令来显示登录路径文件内容,但即使在这种情况下,密码值也会被屏蔽,这样其他用户就不会看到它们。

The obfuscation used by mysql_config_editor prevents passwords from appearing in .mylogin.cnf as cleartext and provides a measure of security by preventing inadvertent password exposure. mysql_config_editor使用的混淆防止密码以明文形式出现在.mylogin.cnf中,并通过防止无意中暴露密码来提供安全措施。For example, if you display a regular unobfuscated my.cnf option file on the screen, any passwords it contains are visible for anyone to see. 例如,如果您在屏幕上显示一个常规的未混淆的my.cnf选项文件,则任何人都可以看到它包含的任何密码。With .mylogin.cnf, that is not true, but the obfuscation used is not likely to deter a determined attacker and you should not consider it unbreakable. 对于.mylogin.cnf,这不是真的,但使用的混淆不太可能阻止一个坚定的攻击者,你不应该认为它牢不可破。A user who can gain system administration privileges on your machine to access your files could unobfuscate the .mylogin.cnf file with some effort.可以在您的计算机上获得系统管理权限以访问您的文件的用户可以通过一些努力来消除.mylogin.cnf文件的混淆。

The login path file must be readable and writable to the current user, and inaccessible to other users. 登录路径文件必须对当前用户可读写,其他用户无法访问。Otherwise, mysql_config_editor ignores it, and client programs do not use it, either.否则,mysql_config_editor会忽略它,客户端程序也不会使用它。

Invoke mysql_config_editor like this:调用mysql_config_editor,如下所示:

mysql_config_editor [program_options] command [command_options]

If the login path file does not exist, mysql_config_editor creates it.如果登录路径文件不存在,mysql_config_editor会创建它。

Command arguments are given as follows:命令参数如下:

The position of the command name within the set of program arguments is significant. For example, these command lines have the same arguments, but produce different results:命令名在程序参数集中的位置很重要。例如,这些命令行具有相同的参数,但产生不同的结果:

mysql_config_editor --help set
mysql_config_editor set --help

The first command line displays a general mysql_config_editor help message, and ignores the set command. The second command line displays a help message specific to the set command.第一个命令行显示一条通用的mysql_config_editor帮助消息,并忽略set命令。第二个命令行显示特定于set命令的帮助消息。

Suppose that you want to establish a client login path that defines your default connection parameters, and an additional login path named remote for connecting to the MySQL server the host remote.example.com. You want to log in as follows:假设您想建立一个定义默认连接参数的client登录路径,以及一个名为remote的附加登录路径,用于连接到MySQL服务器主机remote.example.com。您要按如下方式登录:

To set up the login paths in the .mylogin.cnf file, use the following set commands. Enter each command on a single line, and enter the appropriate passwords when prompted:要在.mylogin.cnf文件中设置登录路径,请使用以下set命令。在一行中输入每个命令,并在提示时输入相应的密码:

shell> mysql_config_editor set --login-path=client
         --host=localhost --user=localuser --password
Enter password: enter password "localpass" here
shell> mysql_config_editor set --login-path=remote
         --host=remote.example.com --user=remoteuser --password
Enter password: enter password "remotepass" here

mysql_config_editor uses the client login path by default, so the --login-path=client option can be omitted from the first command without changing its effect.mysql_config_editor默认使用客户端登录路径,因此可以在不改变其效果的情况下从第一个命令中省略--login-path=client选项。

To see what mysql_config_editor writes to the .mylogin.cnf file, use the print command:要查看mysql_config_editor写入.mylogin.cnf文件的内容,请使用print命令:

shell> mysql_config_editor print --all
[client]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com

The print command displays each login path as a set of lines beginning with a group header indicating the login path name in square brackets, followed by the option values for the login path. Password values are masked and do not appear as cleartext.print命令将每个登录路径显示为一组行,以方括号中指示登录路径名称的组标题开头,后跟登录路径的选项值。密码值被屏蔽,不会以明文形式显示。

If you do not specify --all to display all login paths or --login-path=name to display a named login path, the print command displays the client login path by default, if there is one.如果不指定--all显示所有登录路径或--login-path=name显示命名登录路径,则print命令默认显示客户端登录路径(如果有的话)。

As shown by the preceding example, the login path file can contain multiple login paths. 如上例所示,登录路径文件可以包含多个登录路径。In this way, mysql_config_editor makes it easy to set up multiple personalities for connecting to different MySQL servers, or for connecting to a given server using different accounts. 通过这种方式,mysql_config_editor可以轻松设置多个“个性”,以连接到不同的mysql服务器,或使用不同的帐户连接到给定的服务器。Any of these can be selected by name later using the --login-path option when you invoke a client program. For example, to connect to the remote server, use this command:稍后调用客户端程序时,可以使用--login-path选项按名称选择其中任何一个。例如,要连接到远程服务器,请使用以下命令:

mysql --login-path=remote

Here, mysql reads the [client] and [mysql] option groups from other option files, and the [client], [mysql], and [remote] groups from the login path file.在这里,mysql从其他选项文件中读取[client][mysql]选项组,从登录路径文件中读取[client][mysql][remote]组。

To connect to the local server, use this command:要连接到本地服务器,请使用以下命令:

mysql --login-path=client

Because mysql reads the client and mysql login paths by default, the --login-path option does not add anything in this case. That command is equivalent to this one:因为mysql默认读取clientmysql登录路径,所以--login-path选项在这种情况下不会添加任何内容。该命令与以下命令等效:

mysql

Options read from the login path file take precedence over options read from other option files. Options read from login path groups appearing later in the login path file take precedence over options read from groups appearing earlier in the file.从登录路径文件中读取的选项优先于从其他选项文件读取的选项。从登录路径文件中稍后出现的登录路径组中读取的选项优先于从文件中较早出现的组读取的选项。

mysql_config_editor adds login paths to the login path file in the order you create them, so you should create more general login paths first and more specific paths later. If you need to move a login path within the file, you can remove it, then recreate it to add it to the end. mysql_config_editor按照创建登录路径的顺序将登录路径添加到登录路径文件中,因此您应该先创建更通用的登录路径,然后再创建更具体的路径。如果需要在文件中移动登录路径,可以将其删除,然后重新创建以将其添加到末尾。For example, a client login path is more general because it is read by all client programs, whereas a mysqldump login path is read only by mysqldump. 例如,客户端登录路径更通用,因为它被所有客户端程序读取,而mysqldump登录路径仅由mysqldump读取。Options specified later override options specified earlier, so putting the login paths in the order client, mysqldump enables mysqldump-specific options to override client options.稍后指定的选项会覆盖之前指定的选项,因此将登录路径按client顺序排列,mysqldump启用mysqldump特定的选项来覆盖客户端选项。

When you use the set command with mysql_config_editor to create a login path, you need not specify all possible option values (host name, user name, password, port, socket). Only those values given are written to the path. 当您使用mysql_config_editorset命令创建登录路径时,您不需要指定所有可能的选项值(主机名、用户名、密码、端口、套接字)。只有给定的值才会写入路径。Any missing values required later can be specified when you invoke a client path to connect to the MySQL server, either in other option files or on the command line. 当您调用客户端路径连接到MySQL服务器时,可以在其他选项文件或命令行中指定稍后需要的任何缺失值。Any options specified on the command line override those specified in the login path file or other option files. 命令行上指定的任何选项都会覆盖登录路径文件或其他选项文件中指定的选项。For example, if the credentials in the remote login path also apply for the host remote2.example.com, connect to the server on that host like this:例如,如果remote登录路径中的凭据也适用于主机remote2.example.com,请按如下方式连接到该主机上的服务器:

mysql --login-path=remote --host=remote2.example.com

mysql_config_editor General Options常规选项

mysql_config_editor supports the following general options, which may be used preceding any command named on the command line. mysql_config_editor支持以下常规选项,这些选项可以在命令行上命名的任何命令之前使用。For descriptions of command-specific options, see mysql_config_editor Commands and Command-Specific Options.有关命令特定选项的描述,请参阅mysql_config_editor命令和命令特定选项

Table 4.20 mysql_config_editor General Options常规选项

Option Name选项名称Description描述
--debugWrite debugging log写入调试日志
--helpDisplay help message and exit显示帮助消息并退出
--verboseVerbose mode详细模式
--versionDisplay version information and exit显示版本信息并退出

mysql_config_editor Commands and Command-Specific Options命令和命令特定选项

This section describes the permitted mysql_config_editor commands, and, for each one, the command-specific options permitted following the command name on the command line.本节介绍允许的mysql_config_editor命令,以及对于每个命令,在命令行上命令名后允许的命令特定选项。

In addition, mysql_config_editor supports general options that can be used preceding any command. 此外,mysql_config_editor支持在任何命令之前使用的常规选项。For descriptions of these options, see mysql_config_editor General Options.有关这些选项的说明,请参阅mysql_config_editor常规选项

mysql_config_editor supports these commands:mysql_config_editor支持以下命令: