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.它可以启动或停止服务器,或报告其当前状态。
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 mysqld_multi在[mysqld
in N
]my.cnf
(or in the file named by the --defaults-file
option). my.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
. GNR
。Group 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的[mysqld]组中使用的选项相同。[mysqld]
group used for starting 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. start
、stop
、reload
(停止和重新启动)和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按如下方式搜索选项文件:
With 使用--no-defaults
, no option files are read.--no-defaults
时,不会读取选项文件。
With 使用--defaults-file=
, only the named file is read.file_name
--defaults-file=file_name
,只读取指定的文件。
Otherwise, option files in the standard list of locations are read, including any file named by the 否则,将读取标准位置列表中的选项文件,包括由--defaults-extra-file=
option, if one is given. (If the option is given multiple times, the last value is used.)file_name
--defaults-extra-file=file_name
选项命名的任何文件(如果有)。(如果多次给出该选项,则使用最后一个值。)
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 [mysqld
option groups. N
][mysqld_multi]
和[mysqldN]
选项组。The [mysqld_multi]
group can be used for options to mysqld_multi itself. [mysqld_multi]
组可用于mysqld_multi本身的选项。[mysqld
groups can be used for options passed to specific mysqld instances.N
][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]
组可用于mysqld或mysqld_safe的所有实例读取的常见选项。You can specify a 您可以指定--defaults-file=
option to use a different configuration file for that instance, in which case the file_name
[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支持以下选项。
Display a help message and exit.显示帮助消息并退出。
Display a sample option file.显示示例选项文件。
Specify the name of the log file. If the file exists, log output is appended to it.指定日志文件的名称。如果文件存在,则日志输出将附加到该文件。
The mysqladmin binary to be used to stop servers.用于停止服务器的mysqladmin二进制文件。
The mysqld binary to be used. 要使用的mysqld二进制文件。Note that you can specify mysqld_safe as the value for this option also. 请注意,您也可以将mysqld_safe指定为此选项的值。If you use mysqld_safe to start the server, you can include the 如果使用mysqld_safe启动服务器,则可以在相应的mysqld
or ledir
options in the corresponding [mysqld
option group. N
][mysqldN]
选项组中包含mysqld
或ledir
选项。These options indicate the name of the server that mysqld_safe should start and the path name of the directory where the server is located. 这些选项指示mysqld_safe应启动的服务器的名称以及服务器所在目录的路径名。(See the descriptions for these options in Section 4.3.2, “mysqld_safe — MySQL Server Startup Script”.) Example:(请参阅第4.3.2节,“mysqld_safe--MySQL服务器启动脚本”中这些选项的描述。)示例:
[mysqld38] mysqld = mysqld-debug ledir = /opt/local/mysql/libexec
Print log information to 将日志信息打印到stdout
rather than to the log file. By default, output goes to the log file.stdout
,而不是日志文件。默认情况下,输出会进入日志文件。
The password of the MySQL account to use when invoking mysqladmin. 调用mysqladmin时使用的MySQL帐户的密码。Note that the password value is not optional for this option, unlike for other MySQL programs.请注意,与其他MySQL程序不同,此选项的密码值不是可选的。
Silent mode; disable warnings.静音模式;禁用警告。
Connect to each MySQL server through the TCP/IP port instead of the Unix socket file. 通过TCP/IP端口而不是Unix套接字文件连接到每个MySQL服务器。(If a socket file is missing, the server might still be running, but accessible only through the TCP/IP port.) (如果缺少套接字文件,服务器可能仍在运行,但只能通过TCP/IP端口访问。)By default, connections are made using the Unix socket file. 默认情况下,使用Unix套接字文件进行连接。This option affects 此选项影响stop
and report
operations.stop
和report
操作。
The user name of the MySQL account to use when invoking mysqladmin.调用mysqladmin时使用的MySQL帐户的用户名。
Be more verbose.说得更详细些。
Display version information and exit.显示版本信息并退出。
Some notes about mysqld_multi:关于mysqld_multi的一些注意事项:
Most important: Before using mysqld_multi be sure that you understand the meanings of the options that are passed to the mysqld servers and why you would want to have separate mysqld processes. 最重要的是:在使用mysqld_multi之前,请确保您了解传递给mysqld服务器的选项的含义,以及为什么要有单独的mysqld进程。Beware of the dangers of using multiple mysqld servers with the same data directory. 小心使用具有相同数据目录的多个mysqld服务器的危险。Use separate data directories, unless you know what you are doing. 除非你知道自己在做什么,否则请使用单独的数据目录。Starting multiple servers with the same data directory does not give you extra performance in a threaded system. 在线程化系统中,使用相同的数据目录启动多个服务器并不能为您带来额外的性能。See Section 5.8, “Running Multiple MySQL Instances on One Machine”.请参阅第5.8节,“在一台机器上运行多个MySQL实例”。
Make sure that the data directory for each server is fully accessible to the Unix account that the specific mysqld process is started as. 确保启动特定mysqld进程的Unix帐户可以完全访问每个服务器的数据目录。Do not use the Unix 除非你知道自己在做什么,否则不要使用Unix root帐户。请参阅第6.1.5节,“如何以普通用户身份运行MySQL”。root
account for this, unless you know what you are doing. See Section 6.1.5, “How to Run MySQL as a Normal User”.
Make sure that the MySQL account used for stopping the mysqld servers (with the mysqladmin program) has the same user name and password for each server. 确保用于停止mysqld服务器(使用mysqladmin程序)的MySQL帐户对每台服务器具有相同的用户名和密码。Also, make sure that the account has the 此外,请确保该帐户具有SHUTDOWN
privilege. SHUTDOWN
(关机)权限。If the servers that you want to manage have different user names or passwords for the administrative accounts, you might want to create an account on each server that has the same user name and password. 如果要管理的服务器具有不同的管理帐户用户名或密码,则可能需要在每台服务器上创建一个具有相同用户名和密码的帐户。For example, you might set up a common 例如,您可以通过为每台服务器执行以下命令来设置一个通用的multi_admin
account by executing the following commands for each server:multi_admin
帐户:
shell>mysql -u root -S /tmp/mysql.sock -p
Enter password: mysql>CREATE USER 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
mysql>GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost';
See Section 6.2, “Access Control and Account Management”. You have to do this for each mysqld server. 请参阅第6.2节,“访问控制和帐户管理”。您必须为每个mysqld服务器执行此操作。Change the connection parameters appropriately when connecting to each one. 连接到每个连接参数时,请适当更改连接参数。Note that the host name part of the account name must permit you to connect as 请注意,帐户名的主机名部分必须允许您从要运行mysqld_multi的主机以multi_admin
from the host where you want to run mysqld_multi.multi_admin
身份连接。
The Unix socket file and the TCP/IP port number must be different for every mysqld. 每个mysqld的Unix套接字文件和TCP/IP端口号必须不同。(Alternatively, if the host has multiple network addresses, you can set the (或者,如果主机有多个网络地址,您可以设置bind_address
system variable to cause different servers to listen to different interfaces.)bind_address
系统变量,使不同的服务器监听不同的接口。)
The 如果您使用mysqld_safe启动mysqld(例如,--pid-file
option is very important if you are using mysqld_safe to start mysqld (for example, --mysqld=mysqld_safe
) Every mysqld should have its own process ID file. --mysqld=mysqld_safe
),则--pid-file
选项非常重要。每个mysqld都应该有自己的进程ID文件。The advantage of using mysqld_safe instead of mysqld is that mysqld_safe monitors its mysqld process and restarts it if the process terminates due to a signal sent using 使用mysqld_safe而不是mysqld的优点是,mysqld_safe会监视其mysqld进程,并在进程因使用kill -9
or for other reasons, such as a segmentation fault.kill -9
发送的信号或其他原因(如分段错误)而终止时重新启动它。
You might want to use the 您可能希望为mysqld使用--user
option for mysqld, but to do this you need to run the mysqld_multi script as the Unix superuser (root
). --user
选项,但要做到这一点,您需要以Unix超级用户(root)身份运行mysqld_multi脚本。Having the option in the option file doesn't matter; you just get a warning if you are not the superuser and the mysqld processes are started under your own Unix account.在选项文件中拥有选项并不重要;如果你不是超级用户,并且mysqld进程是在你自己的Unix帐户下启动的,你只会收到一条警告。
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 示例中故意省略了第一组和第五组[mysqld
groups were intentionally omitted from the example to illustrate that you can have “gaps” in the option file. This gives you more flexibility.N
][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节,“使用选项文件”。