文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 6 个 MySQL 程序 / 6.6 管理和实用程序 / 6.6.7 mysql_config_editor — MySQL 配置实用程序
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 88%

6.6.7 mysql_config_editor — MySQL 配置工具6.6.7 mysql_config_editor — MySQL Configuration Utility

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=name 选项来明确指示要使用的登录路径。mysql_config_editor operates on the client login path by default if you specify no --login-path=name option to indicate explicitly which login path to use.

  • 如果没有 --login-path 选项,客户端程序会从登录路径文件读取相同的选项组,就像它们从其他选项文件读取的一样。考虑以下命令:Without a --login-path option, 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-path option, 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-defaults option is used, unless --no-login-paths is set. This permits passwords to be specified in a safer way than on the command line even if --no-defaults is 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_options consists of general mysql_config_editor options.

  • command 指示对 .mylogin.cnf 登录路径文件执行的操作。例如,set 将登录路径写入文件,remove 删除登录路径,print 显示登录路径内容。command indicates what action to perform on the .mylogin.cnf login path file. For example, set writes a login path to the file, remove removes a login path, and print displays login path contents.

  • command_options 指示命令的任何特定附加选项,例如登录路径名称及登录路径中使用的值。command_options indicates 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 of localuser and localpass

  • 连接到远程服务器,用户名和密码分别为 remoteuser 和 remotepassTo the remote server with a user name and password of remoteuser and remotepass

要在 .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 --password
Enter password: enter password "localpass" here
$> mysql_config_editor set --login-path=remote
         --host=remote.example.com --user=remoteuser --password
Enter 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=name 来显示指定的登录路径,则 print 命令默认显示 client 登录路径(如果存在)。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.

如前面的示例所示,登录路径文件可以包含多个登录路径。通过这种方式,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.

表 6.18 mysql_config_editor 常规选项Table 6.18 mysql_config_editor General Options

选项名称Option Name 说明Description
--调试--debug 写调试日志Write debugging log
--帮助--help 显示帮助信息并退出Display help message and exit
--详细--verbose 详细模式Verbose mode
--版本--version 显示版本信息并退出Display version information and exit

  • --help, -? --help, -?

    命令行格式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, where command is a command other than help:

    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_name。默认值为 d:t:o,/tmp/mysql_config_editor.trace。Write a debugging log. A typical debug_options string is d:t:o,file_name. The default is d:t:o,/tmp/mysql_config_editor.trace.

    此选项仅在 MySQL 使用 WITH_DEBUG 构建时可用。Oracle 提供的 MySQL 发行版二进制文件 未 使用此选项构建。This option is available only if MySQL was built using WITH_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, where command is a command other than help:

    mysql_config_editor command --help
    
  • print [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 is client if no login path is named. If both --all and --login-path are given, --all takes precedence.

    print 命令允许在命令名称后使用以下选项:The print command permits these options following the command name:

    • --help, -?

      显示 print 命令的帮助信息并退出。Display a help message for the print command 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, -G name

      打印指定登录路径的内容。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 --user options. If none of those options are given, remove removes the entire login path. For example, this command removes only the user option from the mypath login path rather than the entire mypath login path:

    mysql_config_editor remove --login-path=mypath --user
    

    此命令删除整个 mypath 登录路径:This command removes the entire mypath login path:

    mysql_config_editor remove --login-path=mypath
    

    remove 命令在命令名称后允许这些选项:The remove command permits these options following the command name:

    • --help, -?

      显示 remove 命令的帮助信息并退出。Display a help message for the remove command 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, -G name

      要删除或修改的登录路径。如果未提供此选项,默认的登录路径名称为client。The login path to remove or modify. The default login path name is client if 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=client was not specified. This option is enabled by default; use --skip-warn to disable it.

  • reset [options]reset [options]

    清空登录路径文件的内容。Empty the contents of the login path file.

    reset 命令在命令名称后允许以下选项:The reset command permits these options following the command name:

  • 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 --user options. If none of those options are given, mysql_config_editor writes the login path as an empty group.

    set 命令允许在命令名称后使用这些选项:The set command permits these options following the command name:

    • --help, -?

      显示 set 命令的帮助信息并退出。Display a help message for the set command 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, -h host_name

      要写入登录路径的主机名。The host name to write to the login path.

    • --login-path=name, -G name--login-path=name, -G name

      要创建的登录路径。如果未提供此选项,默认的登录路径名称为client。The login path to create. The default login path name is client if 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, -P port_num

      写入登录路径的 TCP/IP 端口号。The TCP/IP port number to write to the login path.

    • --socket=file_name, -S file_name--socket=file_name, -S file_name

      写入登录路径的 Unix 套接字文件名。The Unix socket file name to write to the login path.

    • --user=user_name, -u user_name--user=user_name, -u user_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-warn to disable it.