mysql_config_editor 工具允许你将认证凭据存储在名为 .mylogin.cnf 的加密登录路径文件中。该文件的位置在 Windows 系统上为 %APPDATA%\MySQL 目录,在非 Windows 系统上为当前用户的主目录。MySQL 客户端程序之后可以读取该文件,以获取连接 MySQL 服务器所需的认证凭据。The mysql_config_editor utility enables you
to store authentication credentials in an obfuscated login path
file named .mylogin.cnf. The file location
is the %APPDATA%\MySQL directory on Windows
and the current user's home directory on non-Windows systems.
The file can be read later by MySQL client programs to obtain
authentication credentials for connecting to MySQL Server.
.mylogin.cnf 登录路径文件的未混淆格式由选项组组成,类似于其他选项文件。.mylogin.cnf 中的每个选项组称为 “登录路径”,这是一个只允许某些选项的组:host、user、password、port 和 socket。可以将登录路径选项组视为一组选项,用于指定连接哪个 MySQL 服务器以及使用哪个帐户进行身份验证。下面是一个未混淆的示例:The unobfuscated format of the .mylogin.cnf
login path file consists of option groups, similar to other
option files. 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. Think 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:
[client] user = mydefaultname password = mydefaultpass host = 127.0.0.1 [mypath] user = myothername password = myotherpass host = localhost
当您调用客户端程序连接到服务器时,客户端会将 .mylogin.cnf 与其他选项文件一起使用。它的优先级高于其他选项文件,但低于在客户端命令行上显式指定的选项。有关选项文件使用顺序的信息,请参见 第 6.2.2.2 节,“使用选项文件”。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. For information about the order in which
option files are used, see Section 6.2.2.2, “Using Option Files”.
要指定备用登录路径文件名,请设置 MYSQL_TEST_LOGIN_FILE 环境变量。此变量可被 mysql_config_editor、标准 MySQL 客户端(mysql、mysqladmin 等)以及 mysql-test-run.pl 测试工具识别。To specify an alternate login path file name, set the
MYSQL_TEST_LOGIN_FILE environment variable.
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.
程序在登录路径文件中使用组,如下所示:Programs use groups in the login path file as follows:
mysql_config_editor 默认操作
client登录路径,如果您没有指定--login-path=选项来明确指示要使用的登录路径。mysql_config_editor operates on thenameclientlogin path by default if you specify no--login-path=option to indicate explicitly which login path to use.name如果没有
--login-path选项,客户端程序会从登录路径文件读取相同的选项组,就像它们从其他选项文件读取的一样。考虑以下命令:Without a--login-pathoption, client programs read the same option groups from the login path file that they read from other option files. Consider this command:mysql
默认情况下,mysql 客户端会从其他选项文件中读取
[client]和[mysql]组,因此它也会从登录路径文件中读取它们。By default, the mysql client reads the[client]and[mysql]groups from other option files, so it reads them from the login path file as well.使用
--login-path选项时,客户端程序还会从登录路径文件中读取指定的登录路径。从其他选项文件读取的选项组保持不变。考虑以下命令:With a--login-pathoption, client programs additionally read the named login path from the login path file. The option groups read from other option files remain the same. Consider this command:mysql --login-path=mypath
mysql 客户端从其他选项文件中读取
[client]和[mysql],并从登录路径文件中读取[client]、[mysql]和[mypath]。The mysql client reads[client]and[mysql]from other option files, and[client],[mysql], and[mypath]from the login path file.即使使用了
--no-defaults选项,客户端程序仍会读取登录路径文件,除非设置了--no-login-paths。这允许以比在命令行上更安全的方式指定密码,即使存在--no-defaults。Client programs read the login path file even when the--no-defaultsoption is used, unless--no-login-pathsis set. This permits passwords to be specified in a safer way than on the command line even if--no-defaultsis present.
mysql_config_editor 对 .mylogin.cnf 文件进行混淆处理,因此不能以明文形式读取,并且客户端程序在解密后使用的内容仅存在于内存中。通过这种方式,密码可以以非明文格式存储在文件中,以后使用时无需在命令行或环境变量中暴露。mysql_config_editor 提供了一个 print 命令来显示登录路径文件的内容,但即便在这种情况下,密码值也会被屏蔽,以确保其他用户看不到。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. 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 使用的混淆方法可以防止密码以明文形式出现在 .mylogin.cnf 文件中,并通过防止密码意外泄露提供了一定的安全性。例如,如果你在屏幕上显示普通未混淆的 my.cnf 配置文件,文件中包含的任何密码都会被任何人看到。而使用 .mylogin.cnf 并非如此,但使用的混淆方法不太可能阻止有决心的攻击者,所以不应认为它是无法破解的。能够在你的机器上获得系统管理权限来访问文件的用户,经过一定努力后可以解混淆 .mylogin.cnf 文件。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.
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. 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. A user who can gain
system administration privileges on your machine to access your
files could unobfuscate the .mylogin.cnf
file with some effort.
登录路径文件必须对当前用户可读可写,并且对其他用户不可访问。否则,mysql_config_editor 会忽略它,客户端程序也不会使用它。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 [program_options]command[command_options]
如果登录路径文件不存在,mysql_config_editor 会创建它。If the login path file does not exist, mysql_config_editor creates it.
命令参数如下所示:Command arguments are given as follows:
program_options包含通用的 mysql_config_editor 选项。program_optionsconsists of general mysql_config_editor options.command指示对.mylogin.cnf登录路径文件执行的操作。例如,set将登录路径写入文件,remove删除登录路径,print显示登录路径内容。commandindicates what action to perform on the.mylogin.cnflogin path file. For example,setwrites a login path to the file,removeremoves a login path, andprintdisplays login path contents.command_options指示命令的任何特定附加选项,例如登录路径名称及登录路径中使用的值。command_optionsindicates any additional options specific to the command, such as the login path name and the values to use in the login path.
命令名称在程序参数集合中的位置是重要的。例如,这些命令行具有相同的参数,但产生不同的结果: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
第一条命令行显示了一般的 mysql_config_editor 帮助信息,并忽略 set 命令。第二条命令行显示了 set 命令的特定帮助信息。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.
假设你想建立一个 client 登录路径,用于定义你的默认连接参数,并建立一个额外的登录路径,名为 remote,用于连接 MySQL 服务器主机 remote.example.com。你想按以下方式登录: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:
默认情况下,连接到本地服务器,用户名和密码为
localuser和localpassBy default, to the local server with a user name and password oflocaluserandlocalpass连接到远程服务器,用户名和密码分别为
remoteuser和remotepassTo the remote server with a user name and password ofremoteuserandremotepass
要在 .mylogin.cnf 文件中设置登录路径,请使用以下 set 命令。每个命令单独输入一行,并在提示时输入相应的密码: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:
$>mysql_config_editor set --login-path=client --host=localhost --user=localuser --passwordEnter password:enter password "localpass" here$>mysql_config_editor set --login-path=remote --host=remote.example.com --user=remoteuser --passwordEnter password:enter password "remotepass" here
mysql_config_editor 默认使用 client 登录路径,因此第一条命令中可以省略 --login-path=client 选项,而不会改变其效果。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 写入 .mylogin.cnf 文件的内容,请使用 print 命令:To see what mysql_config_editor writes to the
.mylogin.cnf file, use the
print command:
$> mysql_config_editor print --all
[client]
user = localuser
password = *****
host = localhost
[remote]
user = remoteuser
password = *****
host = remote.example.com
print 命令将每个登录路径显示为一组以组标题开头的行,标题以方括号表示登录路径名称,随后是该登录路径的选项值。密码值会被遮蔽,不会以明文显示。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.
如果没有指定 --all 来显示所有登录路径,或者没有指定 --login-path= 来显示指定的登录路径,则 nameprint 命令默认显示 client 登录路径(如果存在)。If you do not specify --all to display all
login paths or
--login-path= to
display a named login path, the nameprint command
displays the client login path by default, if
there is one.
如前面的示例所示,登录路径文件可以包含多个登录路径。通过这种方式,mysql_config_editor 可以轻松设置多个用于连接不同 MySQL 服务器的“身份”,或者用于使用不同账户连接同一服务器。稍后在调用客户端程序时,可以使用 --login-path 选项按名称选择其中任何一个。例如,要连接到远程服务器,请使用以下命令: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. 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:
mysql --login-path=remote
这里,mysql 从其他选项文件读取 [client] 和 [mysql] 选项组,并从登录路径文件读取 [client]、[mysql] 和 [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.
要连接到本地服务器,请使用此命令:To connect to the local server, use this command:
mysql --login-path=client
因为 mysql 默认会读取 client 和 mysql 登录路径,所以在这种情况下 --login-path 选项没有增加任何内容。该命令等价于以下命令: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
从登录路径文件读取的选项优先于从其他选项文件读取的选项。从登录路径文件中出现较后的登录路径组读取的选项优先于从文件中较早出现的组读取的选项。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 会按你创建的顺序将登录路径添加到登录路径文件中,因此你应先创建更通用的登录路径,然后再创建更具体的路径。如果你需要在文件中移动某个登录路径,可以先删除它,然后重新创建以将其添加到末尾。例如,client 登录路径更通用,因为它会被所有客户端程序读取,而 mysqldump 登录路径仅被 mysqldump 读取。后指定的选项会覆盖先前指定的选项,因此按 client、mysqldump 的顺序放置登录路径,可以使 mysqldump 特定选项覆盖 client 选项。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. 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. 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.
当您使用 set 命令和 mysql_config_editor 创建登录路径时,不需要指定所有可能的选项值(主机名、用户名、密码、端口、套接字)。只有提供的值会被写入路径。稍后需要的任何缺失值可以在调用客户端路径连接到 MySQL 服务器时指定,无论是在其他选项文件中还是在命令行上。命令行中指定的任何选项都会覆盖登录路径文件或其他选项文件中指定的选项。例如,如果 remote 登录路径中的凭据也适用于主机 remote2.example.com,则可以这样连接该主机上的服务器: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. 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. 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:
mysql --login-path=remote --host=remote2.example.com
mysql_config_editor 常规选项mysql_config_editor General Options
mysql_config_editor 支持以下常规选项,这些选项可以在命令行中任何命名前使用。有关命令特定选项的描述,请参阅 mysql_config_editor 命令及命令特定选项。mysql_config_editor supports the following general options, which may be used preceding any command named on the command line. For descriptions of command-specific options, see mysql_config_editor Commands and Command-Specific Options.
命令行格式Command-Line Format --help--help显示一般帮助信息并退出。Display a general help message and exit.
要查看特定命令的帮助信息,请按如下方式调用 mysql_config_editor,其中
command是除help之外的命令:To see a command-specific help message, invoke mysql_config_editor as follows, wherecommandis a command other thanhelp:mysql_config_editor
command--help--debug[=,debug_options]-#debug_options命令行格式Command-Line Format --debug[=debug_options]--debug[=debug_options]类型Type 字符串String 默认值Default Value d:t:o写入调试日志。一个典型的
debug_options字符串是d:t:o,。默认值为file_named:t:o,/tmp/mysql_config_editor.trace。Write a debugging log. A typicaldebug_optionsstring isd:t:o,. The default isfile_named:t:o,/tmp/mysql_config_editor.trace.此选项仅在 MySQL 使用
WITH_DEBUG构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built usingWITH_DEBUG. MySQL release binaries provided by Oracle are not built using this option.--verbose,-v命令行格式Command-Line Format --verbose--verbose详细模式。打印更多有关程序执行内容的信息。如果某个操作没有达到预期效果,此选项可能有助于诊断问题。Verbose mode. Print more information about what the program does. This option may be helpful in diagnosing problems if an operation does not have the effect you expect.
--version,-V命令行格式Command-Line Format --version显示版本信息并退出。Display version information and exit.
mysql_config_editor 命令及命令特定选项mysql_config_editor Commands and Command-Specific Options
本节描述允许使用的 mysql_config_editor 命令,以及每个命令在命令行中命令名之后允许使用的命令特定选项。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 支持可以在任何命令前使用的一般选项。有关这些选项的描述,请参见 mysql_config_editor 一般选项。In addition, mysql_config_editor supports general options that can be used preceding any command. For descriptions of these options, see mysql_config_editor General Options.
mysql_config_editor 支持以下命令:mysql_config_editor supports these commands:
helphelp显示一般帮助信息并退出。此命令不接受后续选项。Display a general help message and exit. This command takes no following options.
要查看特定命令的帮助信息,请按如下方式调用 mysql_config_editor,其中
command是除help之外的命令:To see a command-specific help message, invoke mysql_config_editor as follows, wherecommandis a command other thanhelp:mysql_config_editor
command--helpprint [options]print [options]以未混淆的形式打印登录路径文件的内容,但密码显示为
*****。Print the contents of the login path file in unobfuscated form, with the exception that passwords are displayed as*****.如果未指定登录路径名称,默认的登录路径名称为
client。如果同时提供了--all和--login-path,则--all优先。The default login path name isclientif no login path is named. If both--alland--login-pathare given,--alltakes precedence.print命令允许在命令名称后使用以下选项:Theprintcommand permits these options following the command name:--help,-?显示
print命令的帮助信息并退出。Display a help message for theprintcommand and exit.要查看常规帮助信息,请使用 mysql_config_editor --help。To see a general help message, use mysql_config_editor --help.
--all打印登录路径文件中所有登录路径的内容。Print the contents of all login paths in the login path file.
--login-path=name,-G name--login-path=,name-Gname打印指定登录路径的内容。Print the contents of the named login path.
remove [options]remove [options]从登录路径文件中移除登录路径,或通过从中删除选项来修改登录路径。Remove a login path from the login path file, or modify a login path by removing options from it.
此命令仅从登录路径中删除使用
--host、--password、--port、--socket和--user选项指定的选项。如果未提供这些选项中的任何一个,remove将删除整个登录路径。例如,此命令仅从mypath登录路径中删除user选项,而不是整个mypath登录路径:This command removes from the login path only such options as are specified with the--host,--password,--port,--socket, and--useroptions. If none of those options are given,removeremoves the entire login path. For example, this command removes only theuseroption from themypathlogin path rather than the entiremypathlogin path:mysql_config_editor remove --login-path=mypath --user
此命令删除整个
mypath登录路径:This command removes the entiremypathlogin path:mysql_config_editor remove --login-path=mypath
remove命令在命令名称后允许这些选项:Theremovecommand permits these options following the command name:--help,-?显示
remove命令的帮助信息并退出。Display a help message for theremovecommand and exit.要查看常规帮助信息,请使用 mysql_config_editor --help。To see a general help message, use mysql_config_editor --help.
--host,-h从登录路径中移除主机名。Remove the host name from the login path.
--login-path=name,-G name--login-path=,name-Gname要删除或修改的登录路径。如果未提供此选项,默认的登录路径名称为
client。The login path to remove or modify. The default login path name isclientif this option is not given.--password,-p从登录路径中移除密码。Remove the password from the login path.
--port,-P--port,-P从登录路径中移除 TCP/IP 端口号。Remove the TCP/IP port number from the login path.
--socket,-S从登录路径中移除 Unix 套接字文件名。Remove the Unix socket file name from the login path.
--user,-u从登录路径中移除用户名。Remove the user name from the login path.
--warn,-w如果命令尝试删除默认登录路径(
client)且未指定--login-path=client,则警告并提示用户确认。此选项默认启用;使用--skip-warn来禁用它。Warn and prompt the user for confirmation if the command attempts to remove the default login path (client) and--login-path=clientwas not specified. This option is enabled by default; use--skip-warnto disable it.
reset [options]reset [options]清空登录路径文件的内容。Empty the contents of the login path file.
reset命令在命令名称后允许以下选项:Theresetcommand permits these options following the command name:--help,-?显示
reset命令的帮助信息并退出。Display a help message for theresetcommand and exit.要查看常规帮助信息,请使用 mysql_config_editor --help。To see a general help message, use mysql_config_editor --help.
set [options]set [options]将登录路径写入登录路径文件。Write a login path to the login path file.
该命令仅将使用
--host、--password、--port、--socket和--user选项指定的内容写入登录路径。如果未提供这些选项中的任何一个,mysql_config_editor 将把登录路径写入为空组。This command writes to the login path only such options as are specified with the--host,--password,--port,--socket, and--useroptions. If none of those options are given, mysql_config_editor writes the login path as an empty group.set命令允许在命令名称后使用这些选项:Thesetcommand permits these options following the command name:--help,-?显示
set命令的帮助信息并退出。Display a help message for thesetcommand and exit.要查看常规帮助信息,请使用 mysql_config_editor --help。To see a general help message, use mysql_config_editor --help.
--host=host_name,-h host_name--host=,host_name-hhost_name要写入登录路径的主机名。The host name to write to the login path.
--login-path=name,-G name--login-path=,name-Gname要创建的登录路径。如果未提供此选项,默认的登录路径名称为
client。The login path to create. The default login path name isclientif this option is not given.--password,-p提示输入密码以写入登录路径。在mysql_config_editor显示提示后,输入密码并按 Enter。为了防止其他用户看到密码,mysql_config_editor不会回显密码。Prompt for a password to write to the login path. After mysql_config_editor displays the prompt, type the password and press Enter. To prevent other users from seeing the password, mysql_config_editor does not echo it.
要指定一个空密码,在密码提示符处按回车。写入登录路径文件的结果登录路径包括如下行:To specify an empty password, press Enter at the password prompt. The resulting login path written to the login path file includes a line like this:
password =
--port=port_num,-P port_num--port=,port_num-Pport_num写入登录路径的 TCP/IP 端口号。The TCP/IP port number to write to the login path.
--socket=file_name,-S file_name--socket=,file_name-Sfile_name写入登录路径的 Unix 套接字文件名。The Unix socket file name to write to the login path.
--user=user_name,-u user_name--user=,user_name-uuser_name要写入登录路径的用户名。The user name to write to the login path.
--warn,-w如果命令尝试覆盖现有登录路径,会警告用户并提示确认。此选项默认启用;使用
--skip-warn可禁用此功能。Warn and prompt the user for confirmation if the command attempts to overwrite an existing login path. This option is enabled by default; use--skip-warnto disable it.