8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 7 MySQL 服务器管理 / 7.8 在一台机器上运行多个 MySQL 实例
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

7.8 在一台机器上运行多个 MySQL 实例7.8 Running Multiple MySQL Instances on One Machine

在某些情况下,你可能希望在单台机器上运行多个 MySQL 实例。你可能希望在不影响现有生产设置的情况下测试新的 MySQL 版本。或者,你可能希望为不同的用户提供对他们自己管理的不同 mysqld 服务器的访问权限。(例如,你可能是一家互联网服务提供商,想为不同的客户提供独立的 MySQL 安装。)In some cases, you might want to run multiple instances of MySQL on a single machine. You might want to test a new MySQL release while leaving an existing production setup undisturbed. Or you might want to give different users access to different mysqld servers that they manage themselves. (For example, you might be an Internet Service Provider that wants to provide independent MySQL installations for different customers.)

每个实例可以使用不同的 MySQL 服务器二进制文件,也可以多个实例使用相同的二进制文件,或者这两种方法的任意组合。例如,您可以运行一个 MySQL 8.3 的服务器实例和一个 MySQL 8.4 的服务器实例,以查看不同版本如何处理特定工作负载。或者,您可以运行当前生产版本的多个实例,每个实例管理一组不同的数据库。It is possible to use a different MySQL server binary per instance, or use the same binary for multiple instances, or any combination of the two approaches. For example, you might run a server from MySQL 8.3 and one from MySQL 8.4, to see how different versions handle a given workload. Or you might run multiple instances of the current production version, each managing a different set of databases.

无论是否使用不同的服务器二进制文件,运行的每个实例都必须为几个操作参数配置唯一的值。这消除了实例之间可能发生的冲突。参数可以在命令行中设置、在选项文件中设置,或者通过设置环境变量来设置。请参阅第 6.2.2 节,“指定程序选项”。要查看给定实例使用的值,请连接到该实例并执行SHOW VARIABLES语句。Whether or not you use distinct server binaries, each instance that you run must be configured with unique values for several operating parameters. This eliminates the potential for conflict between instances. Parameters can be set on the command line, in option files, or by setting environment variables. See Section 6.2.2, “Specifying Program Options”. To see the values used by a given instance, connect to it and execute a SHOW VARIABLES statement.

MySQL 实例管理的主要资源是数据目录。每个实例应该使用不同的数据目录,其位置可以通过 --datadir=dir_name 选项来指定。有关为每个实例配置自己的数据目录的方法,以及未能这样做的危险警告,请参阅 第 7.8.1 节,“设置多个数据目录”。The primary resource managed by a MySQL instance is the data directory. Each instance should use a different data directory, the location of which is specified using the --datadir=dir_name option. For methods of configuring each instance with its own data directory, and warnings about the dangers of failing to do so, see Section 7.8.1, “Setting Up Multiple Data Directories”.

除了使用不同的数据目录外,每个服务器实例的几个其他选项也必须具有不同的值:In addition to using different data directories, several other options must have different values for each server instance:

  • --port=port_num--port=port_num

    --port 控制 TCP/IP 连接的端口号。或者,如果主机有多个网络地址,你可以设置 bind_address 系统变量,以使每个服务器监听不同的地址。--port controls the port number for TCP/IP connections. Alternatively, if the host has multiple network addresses, you can set the bind_address system variable to cause each server to listen to a different address.

  • --socket={file_name|pipe_name}--socket={file_name|pipe_name}

    --socket 控制 Unix 上的 Unix 套接字文件路径或 Windows 上的命名管道名称。在 Windows 上,仅对于配置为允许命名管道连接的服务器,有必要指定不同的管道名称。--socket controls the Unix socket file path on Unix or the named-pipe name on Windows. On Windows, it is necessary to specify distinct pipe names only for those servers configured to permit named-pipe connections.

  • --shared-memory-base-name=name--shared-memory-base-name=name

    此选项仅在 Windows 上使用。它指定 Windows 服务器用于允许客户端通过共享内存连接的共享内存名称。仅对于配置为允许共享内存连接的服务器,才有必要指定不同的共享内存名称。This option is used only on Windows. It designates the shared-memory name used by a Windows server to permit clients to connect using shared memory. It is necessary to specify distinct shared-memory names only for those servers configured to permit shared-memory connections.

  • --pid-file=file_name--pid-file=file_name

    此选项指示服务器写入其进程 ID 的文件的路径名称。This option indicates the path name of the file in which the server writes its process ID.

如果使用以下日志文件选项,则每个服务器的值必须不同:If you use the following log file options, their values must differ for each server:

有关日志文件选项的进一步讨论,请参见 第 7.4 节,“MySQL 服务器日志”。For further discussion of log file options, see Section 7.4, “MySQL Server Logs”.

为了获得更好的性能,你可以为每个服务器以不同的方式指定以下选项,以在多个物理磁盘之间分散负载:To achieve better performance, you can specify the following option differently for each server, to spread the load between several physical disks:

拥有不同的临时目录也使得更容易确定是哪个 MySQL 服务器创建了任何给定的临时文件。Having different temporary directories also makes it easier to determine which MySQL server created any given temporary file.

如果您在不同位置有多个 MySQL 安装,您可以使用 --basedir=dir_name 选项为每个安装指定基本目录。这会使每个实例自动使用不同的数据目录、日志文件和 PID 文件,因为这些参数的默认值都是相对于基本目录的。在这种情况下,您只需指定其他选项 --socket 和 --port。假设您使用 tar 文件二进制发行版安装不同版本的 MySQL。这些安装在不同的位置,因此您可以在其相应的基本目录下使用命令 bin/mysqld_safe 启动每个安装的服务器。mysqld_safe 会确定要传递给 mysqld 的正确 --basedir 选项,您只需将 --socket 和 --port 选项指定给 mysqld_safe 即可。If you have multiple MySQL installations in different locations, you can specify the base directory for each installation with the --basedir=dir_name option. This causes each instance to automatically use a different data directory, log files, and PID file because the default for each of those parameters is relative to the base directory. In that case, the only other options you need to specify are the --socket and --port options. Suppose that you install different versions of MySQL using tar file binary distributions. These install in different locations, so you can start the server for each installation using the command bin/mysqld_safe under its corresponding base directory. mysqld_safe determines the proper --basedir option to pass to mysqld, and you need specify only the --socket and --port options to mysqld_safe.

如以下各节所讨论,通过指定适当的命令选项或设置环境变量,可以启动额外的服务器。然而,如果您需要更长期地运行多个服务器,使用选项文件为每个服务器指定那些必须唯一的选项值会更加方便。--defaults-file 选项在此情况下非常有用。As discussed in the following sections, it is possible to start additional servers by specifying appropriate command options or by setting environment variables. However, if you need to run multiple servers on a more permanent basis, it is more convenient to use option files to specify for each server those option values that must be unique to it. The --defaults-file option is useful for this purpose.