4.3.4 mysqld_multi — Manage Multiple MySQL Servers管理多个MySQL服务器

mysqld_multi is designed to manage several mysqld processes that listen for connections on different Unix socket files and TCP/IP ports. mysqld_multi旨在管理多个mysqld进程,这些进程监听不同Unix套接字文件和TCP/IP端口上的连接。It can start or stop servers, or report their current status.它可以启动或停止服务器,或报告其当前状态。

Note注意

For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. 对于某些Linux平台,RPM或Debian软件包中的MySQL安装包括用于管理MySQL服务器启动和关闭的systemd支持。On these platforms, mysqld_multi is not installed because it is unnecessary. 在这些平台上,没有安装mysqld_multi,因为它是不必要的。For information about using systemd to handle multiple MySQL instances, see Section 2.5.9, “Managing MySQL Server with systemd”.有关使用systemd处理多个MySQL实例的信息,请参阅第2.5.9节,“使用systemd管理MySQL服务器”

mysqld_multi searches for groups named [mysqldN] in my.cnf (or in the file named by the --defaults-file option). mysqld_multimy.cnf(或由--defaults-file选项命名的文件)中搜索名为[mysqldN]的组。N can be any positive integer. N可以是任何正整数。This number is referred to in the following discussion as the option group number, or GNR. 在下面的讨论中,这个数字被称为期权组号,或GNRGroup numbers distinguish option groups from one another and are used as arguments to mysqld_multi to specify which servers you want to start, stop, or obtain a status report for. 组号将选项组彼此区分开来,并用作mysqld_multi的参数,以指定要启动、停止或获取状态报告的服务器。Options listed in these groups are the same that you would use in the [mysqld] group used for starting mysqld. 这些组中列出的选项与您在用于启动mysqld的[mysqld]组中使用的选项相同。(See, for example, Section 2.10.5, “Starting and Stopping MySQL Automatically”.) (例如,请参阅第2.10.5节,“自动启动和停止MySQL”。)However, when using multiple servers, it is necessary that each one use its own value for options such as the Unix socket file and TCP/IP port number. 但是,当使用多个服务器时,每个服务器都必须使用自己的值作为选项,如Unix套接字文件和TCP/IP端口号。For more information on which options must be unique per server in a multiple-server environment, see Section 5.8, “Running Multiple MySQL Instances on One Machine”.有关在多服务器环境中每个服务器必须唯一的选项的更多信息,请参阅第5.8节,“在一台机器上运行多个MySQL实例”

To invoke mysqld_multi, use the following syntax:要调用mysqld_multi,请使用以下语法:

mysqld_multi [options] {start|stop|reload|report} [GNR[,GNR] ...]

start, stop, reload (stop and restart), and report indicate which operation to perform. startstopreload(停止和重新启动)和report指示要执行的操作。You can perform the designated operation for a single server or multiple servers, depending on the GNR list that follows the option name. 您可以对单个服务器或多个服务器执行指定操作,具体取决于选项名称后面的GNR列表。If there is no list, mysqld_multi performs the operation for all servers in the option file.如果没有列表,mysqld_multi将对选项文件中的所有服务器执行操作。

Each GNR value represents an option group number or range of group numbers. 每个GNR值代表一个选项组号或组号范围。The value should be the number at the end of the group name in the option file. 该值应为选项文件中组名末尾的数字。For example, the GNR for a group named [mysqld17] is 17. 例如,名为[mysqld17]的组的GNR为17。To specify a range of numbers, separate the first and last numbers by a dash. 要指定一个数字范围,请用破折号分隔第一个和最后一个数字。The GNR value 10-13 represents groups [mysqld10] through [mysqld13]. GNR值10-13表示组[mysqld10]到[mysqld13]。Multiple groups or group ranges can be specified on the command line, separated by commas. 可以在命令行上指定多个组或组范围,用逗号分隔。There must be no whitespace characters (spaces or tabs) in the GNR list; anything after a whitespace character is ignored.GNR列表中不得有空格字符(空格或制表符);空格字符之后的任何内容都将被忽略。

This command starts a single server using option group [mysqld17]:此命令使用选项组[mysqld17]启动单个服务器:

mysqld_multi start 17

This command stops several servers, using option groups [mysqld8] and [mysqld10] through [mysqld13]:此命令使用选项组[mysqld8][mysqld10][mysqldl3]停止多个服务器:

mysqld_multi stop 8,10-13

For an example of how you might set up an option file, use this command:有关如何设置选项文件的示例,请使用以下命令:

mysqld_multi --example

mysqld_multi searches for option files as follows:mysqld_multi按如下方式搜索选项文件:

For additional information about these and other option-file options, see Section 4.2.2.3, “Command-Line Options that Affect Option-File Handling”.有关这些和其他选项文件选项的更多信息,请参阅第4.2.2.3节,“影响选项文件处理的命令行选项”

Option files read are searched for [mysqld_multi] and [mysqldN] option groups. 在读取的选项文件中搜索[mysqld_multi][mysqldN]选项组。The [mysqld_multi] group can be used for options to mysqld_multi itself. [mysqld_multi]组可用于mysqld_multi本身的选项。[mysqldN] groups can be used for options passed to specific mysqld instances.[mysqldN]组可用于传递给特定mysqld实例的选项。

The [mysqld] or [mysqld_safe] groups can be used for common options read by all instances of mysqld or mysqld_safe. [mysqld][mysqld_safe]组可用于mysqldmysqld_safe的所有实例读取的常见选项。You can specify a --defaults-file=file_name option to use a different configuration file for that instance, in which case the [mysqld] or [mysqld_safe] groups from that file are used for that instance.您可以指定--defaults-file=file_name选项,为该实例使用不同的配置文件,在这种情况下,该文件中的[mysqld][mysqld_safe]组将用于该实例。

mysqld_multi supports the following options.mysqld_multi支持以下选项。

Some notes about mysqld_multi:关于mysqld_multi的一些注意事项:

The following example shows how you might set up an option file for use with mysqld_multi. 以下示例显示了如何设置用于mysqld_multi的选项文件。The order in which the mysqld programs are started or stopped depends on the order in which they appear in the option file. mysqld程序的启动或停止顺序取决于它们在选项文件中的显示顺序。Group numbers need not form an unbroken sequence. 组号不需要形成连续的序列。The first and fifth [mysqldN] groups were intentionally omitted from the example to illustrate that you can have gaps in the option file. This gives you more flexibility.示例中故意省略了第一组和第五组[mysqldN],以说明选项文件中可能存在“间隙”。这为您提供了更大的灵活性。

# This is an example of a my.cnf file for mysqld_multi.
# Usually this file is located in home dir ~/.my.cnf or /etc/my.cnf

[mysqld_multi]
mysqld     = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user       = multi_admin
password   = my_password

[mysqld2]
socket     = /tmp/mysql.sock2
port       = 3307
pid-file   = /usr/local/mysql/data2/hostname.pid2
datadir    = /usr/local/mysql/data2
language   = /usr/local/mysql/share/mysql/english
user       = unix_user1

[mysqld3]
mysqld     = /path/to/mysqld_safe
ledir      = /path/to/mysqld-binary/
mysqladmin = /path/to/mysqladmin
socket     = /tmp/mysql.sock3
port       = 3308
pid-file   = /usr/local/mysql/data3/hostname.pid3
datadir    = /usr/local/mysql/data3
language   = /usr/local/mysql/share/mysql/swedish
user       = unix_user2

[mysqld4]
socket     = /tmp/mysql.sock4
port       = 3309
pid-file   = /usr/local/mysql/data4/hostname.pid4
datadir    = /usr/local/mysql/data4
language   = /usr/local/mysql/share/mysql/estonia
user       = unix_user3

[mysqld6]
socket     = /tmp/mysql.sock6
port       = 3311
pid-file   = /usr/local/mysql/data6/hostname.pid6
datadir    = /usr/local/mysql/data6
language   = /usr/local/mysql/share/mysql/japanese
user       = unix_user4

See Section 4.2.2.2, “Using Option Files”.请参阅第4.2.2.2节,“使用选项文件”