mysqld_multi 旨在管理多个 mysqld 进程,这些进程监听不同的 Unix 套接字文件和 TCP/IP 端口上的连接。它可以启动或停止服务器,或者报告它们的当前状态。mysqld_multi is designed to manage several mysqld processes that listen for connections on different Unix socket files and TCP/IP ports. It can start or stop servers, or report their current status.
对于某些 Linux 平台,从 RPM 或 Debian 软件包安装 MySQL 时,包括了用于管理 MySQL 服务器启动和关闭的 systemd 支持。在这些平台上,mysqld_multi 不会被安装,因为它没有必要。有关使用 systemd 处理多个 MySQL 实例的信息,请参见 第 2.5.9 节,“使用 systemd 管理 MySQL 服务器”。For some Linux platforms, MySQL installation from RPM or Debian packages includes systemd support for managing MySQL server startup and shutdown. On these platforms, mysqld_multi is not installed because it is unnecessary. For information about using systemd to handle multiple MySQL instances, see Section 2.5.9, “Managing MySQL Server with systemd”.
mysqld_multi 会在 my.cnf(或在 --defaults-file 选项指定的文件中)查找名为 [mysqld 的分组。N]N 可以是任何正整数。以下讨论中,这个数字称为选项组编号,或 GNR。组编号用于区分不同的选项组,并作为 mysqld_multi 的参数,指定要启动、停止或获取状态报告的服务器。列在这些组中的选项与用于启动 mysqld 时在 [mysqld] 组中使用的选项相同。(例如,请参见 第 2.9.5 节,“自动启动和停止 MySQL”。)然而,当使用多个服务器时,每个服务器必须使用自己独有的选项值,例如 Unix 套接字文件和 TCP/IP 端口号。有关在多服务器环境中哪些选项必须唯一的更多信息,请参见 第 7.8 节,“在一台机器上运行多个 MySQL 实例”。mysqld_multi searches for groups named
[mysqld in
N]my.cnf (or in the file named by the
--defaults-file option).
N can be any positive integer. This
number is referred to in the following discussion as the option
group number, or 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.
Options listed in these groups are the same that you would use
in the [mysqld] group used for starting
mysqld. (See, for example,
Section 2.9.5, “Starting and Stopping MySQL Automatically”.) 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. For
more information on which options must be unique per server in a
multiple-server environment, see
Section 7.8, “Running Multiple MySQL Instances on One Machine”.
要调用 mysqld_multi,请使用以下语法:To invoke mysqld_multi, use the following syntax:
mysqld_multi [options] {start|stop|reload|report} [GNR[,GNR] ...]
start、stop、reload(停止并重启)以及 report 表示要执行的操作。您可以根据选项名称后面的 GNR 列表,对单个服务器或多个服务器执行指定操作。如果没有列表,mysqld_multi 将对选项文件中的所有服务器执行该操作。start, stop,
reload (stop and restart), and
report indicate which operation to perform.
You can perform the designated operation for a single server or
multiple servers, depending on the
GNR list that follows the option
name. If there is no list, mysqld_multi
performs the operation for all servers in the option file.
每个 GNR 值表示一个选项组编号或一系列组编号。该值应为选项文件中组名称末尾的数字。例如,名称为 [mysqld17] 的组的 GNR 是 17。要指定一个数字范围,请用短横线分隔起始和结束数字。GNR 值 10-13 表示组 [mysqld10] 到 [mysqld13]。命令行上可以指定多个组或组范围,用逗号分隔。GNR 列表中不能有空白字符(空格或制表符);空白字符之后的内容将被忽略。Each GNR value represents an option
group number or range of group numbers. 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. 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]. 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.
此命令使用选项组 [mysqld17] 启动单个服务器:This command starts a single server using option group
[mysqld17]:
mysqld_multi start 17
此命令停止多个服务器,使用选项组 [mysqld8] 和 [mysqld10] 到 [mysqld13]:This command stops several servers, using option groups
[mysqld8] and [mysqld10]
through [mysqld13]:
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 按如下方式搜索选项文件:mysqld_multi searches for option files as follows:
使用
--no-defaults时,不会读取任何选项文件。 With--no-defaults, no option files are read.命令行格式Command-Line Format --no-defaults--no-defaults类型Type 布尔Boolean 默认值Default Value falsefalse使用
--defaults-file=时,只会读取指定的文件。 Withfile_name--defaults-file=, only the named file is read.file_name命令行格式Command-Line Format --defaults-file=filename--defaults-file=filename类型Type 文件名File name 默认值Default Value [none][none]否则,将读取标准位置列表中的选项文件,包括由
--defaults-extra-file=选项指定的任何文件(如果提供了该选项)。(如果该选项被多次指定,将使用最后一个值。) Otherwise, option files in the standard list of locations are read, including any file named by thefile_name--defaults-extra-file=option, if one is given. (If the option is given multiple times, the last value is used.)file_name命令行格式Command-Line Format --defaults-extra-file=filename--defaults-extra-file=filename类型Type 文件名File name 默认值Default Value [none][none]
有关这些选项文件及其他选项文件选项的更多信息,请参见 第 6.2.2.3 节,“影响选项文件处理的命令行选项”。For additional information about these and other option-file options, see Section 6.2.2.3, “Command-Line Options that Affect Option-File Handling”.
读取的选项文件会搜索 [mysqld_multi] 和 [mysqld 选项组。N][mysqld_multi] 组可用于 mysqld_multi 本身的选项。[mysqld 组可用于传递给特定 mysqld 实例的选项。Option files read are searched for
N][mysqld_multi] and
[mysqld option
groups. The N][mysqld_multi] group can be used
for options to mysqld_multi itself.
[mysqld groups
can be used for options passed to specific
mysqld instances.N]
[mysqld] 或 [mysqld_safe] 组可以用于所有 mysqld 或 mysqld_safe 实例读取的通用选项。您可以指定 --defaults-file= 选项来为该实例使用不同的配置文件,在这种情况下,该实例将使用该文件中的 file_name[mysqld] 或 [mysqld_safe] 组。The [mysqld] or
[mysqld_safe] groups can be used for common
options read by all instances of mysqld or
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.
mysqld_multi 支持以下选项。mysqld_multi supports the following options.
命令行格式Command-Line Format --help--help类型Type 布尔Boolean 默认值Default Value falsefalse显示帮助信息并退出。Display a help message and exit.
命令行格式Command-Line Format --example--example类型Type 布尔Boolean 默认值Default Value falsefalse显示示例选项文件。Display a sample option file.
--log=file_name--log=file_name命令行格式Command-Line Format --log=path--log=path类型Type 文件名File name 默认值Default Value /var/log/mysqld_multi.log指定日志文件的名称。如果文件存在,日志输出将追加到该文件中。Specify the name of the log file. If the file exists, log output is appended to it.
--mysqladmin=prog_name--mysqladmin=prog_name命令行格式Command-Line Format --mysqladmin=file--mysqladmin=file类型Type 文件名File name 默认值Default Value [none][none]用于停止服务器的 mysqladmin 可执行文件。The mysqladmin binary to be used to stop servers.
--mysqld=prog_name--mysqld=prog_name命令行格式Command-Line Format --mysqld=file--mysqld=file类型Type 文件名File name 默认值Default Value [none][none]要使用的 mysqld 二进制文件。请注意,您也可以将此选项的值指定为 mysqld_safe。如果您使用 mysqld_safe 启动服务器,可以在相应的
[mysqld选项组中包含N]mysqld或ledir选项。这些选项指示 mysqld_safe 应启动的服务器名称以及服务器所在目录的路径名。(有关这些选项的说明,请参见 第 6.3.2 节,“mysqld_safe — MySQL 服务器启动脚本”。)示例:The mysqld binary to be used. Note that you can specify mysqld_safe as the value for this option also. If you use mysqld_safe to start the server, you can include themysqldorlediroptions in the corresponding[mysqldoption group. 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. (See the descriptions for these options in Section 6.3.2, “mysqld_safe — MySQL Server Startup Script”.) Example:N][mysqld38] mysqld = mysqld-debug ledir = /opt/local/mysql/libexec
命令行格式Command-Line Format --no-log类型Type 布尔Boolean 默认值Default Value falsefalse将日志信息打印到
stdout而不是日志文件。默认情况下,输出会写入日志文件。Print log information tostdoutrather than to the log file. By default, output goes to the log file.--password=password--password=password命令行格式Command-Line Format --password=string--password=string类型Type 字符串String 默认值Default Value [none][none]用于调用 mysqladmin 时的 MySQL 账户密码。注意,对于此选项,密码值不是可选的,不像其他 MySQL 程序。The password of the MySQL account to use when invoking mysqladmin. Note that the password value is not optional for this option, unlike for other MySQL programs.
命令行格式Command-Line Format --silent类型Type 布尔Boolean 默认值Default Value falsefalse静音模式;禁用警告。Silent mode; disable warnings.
命令行格式Command-Line Format --tcp-ip类型Type 布尔Boolean 默认值Default Value falsefalse通过 TCP/IP 端口连接到每个 MySQL 服务器,而不是通过 Unix 套接字文件。(如果套接字文件丢失,服务器可能仍在运行,但只能通过 TCP/IP 端口访问。)默认情况下,连接使用 Unix 套接字文件。此选项会影响
stop和report操作。Connect to each MySQL server through the TCP/IP port instead of the Unix socket file. (If a socket file is missing, the server might still be running, but accessible only through the TCP/IP port.) By default, connections are made using the Unix socket file. This option affectsstopandreportoperations.--user=user_name--user=user_name命令行格式Command-Line Format --user=name--user=name类型Type 字符串String 默认值Default Value root调用 mysqladmin 时使用的 MySQL 账户用户名。The user name of the MySQL account to use when invoking mysqladmin.
命令行格式Command-Line Format --verbose--verbose类型Type 布尔Boolean 默认值Default Value falsefalse更详细一点。Be more verbose.
命令行格式Command-Line Format --version类型Type 布尔Boolean 默认值Default Value falsefalse显示版本信息并退出。Display version information and exit.
关于 mysqld_multi 的一些笔记:Some notes about mysqld_multi:
最重要的是:在使用之前mysqld_multi确保你理解传递给mysqld服务器的选项的含义,以及为什么你会希望有独立的mysqld进程。注意使用多个mysqld服务器并指向相同数据目录的风险。使用独立的数据目录,除非你知道自己在做什么。在同一个数据目录下启动多个服务器不会在多线程系统中提高额外的性能。详见Section 7.8, “Running Multiple MySQL Instances on One Machine”.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. Beware of the dangers of using multiple mysqld servers with the same data directory. 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 7.8, “Running Multiple MySQL Instances on One Machine”.
Important确保每个服务器的数据目录对启动特定 mysqld 进程的 Unix 账户完全可访问。不要 使用 Unix
root账户,除非你 知道 自己在做什么。参见 第 8.1.5 节,“如何以普通用户身份运行 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. Do not use the Unixrootaccount for this, unless you know what you are doing. See Section 8.1.5, “How to Run MySQL as a Normal User”.确保用于停止 mysqld 服务器的 MySQL 账户(使用 mysqladmin 程序)在每台服务器上具有相同的用户名和密码。同时,确保该账户具有
SHUTDOWN权限。如果你希望管理的服务器在管理账户上使用不同的用户名或密码,你可能需要在每台服务器上创建一个具有相同用户名和密码的账户。例如,你可以通过在每台服务器上执行以下命令来设置一个通用的multi_admin账户: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. Also, make sure that the account has theSHUTDOWNprivilege. 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 commonmulti_adminaccount by executing the following commands for each server:$>
mysql -u root -S /tmp/mysql.sock -pEnter password: mysql>CREATE USER 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';mysql>GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost';请参阅 第 8.2 节,“访问控制和账户管理”。您必须对每个 mysqld 服务器执行此操作。在连接每个服务器时,请适当更改连接参数。请注意,账户名称中的主机名部分必须允许您从希望运行 mysqld_multi 的主机以
multi_admin身份进行连接。See Section 8.2, “Access Control and Account Management”. You have to do this for each mysqld server. 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 asmulti_adminfrom the host where you want to run mysqld_multi.每个 mysqld 的 Unix 套接字文件和 TCP/IP 端口号必须不同。(或者,如果主机有多个网络地址,你可以设置
bind_address系统变量,使不同的服务器监听不同的接口。)The Unix socket file and the TCP/IP port number must be different for every mysqld. (Alternatively, if the host has multiple network addresses, you can set thebind_addresssystem variable to cause different servers to listen to different interfaces.)如果你使用 mysqld_safe 来启动 mysqld(例如,
--mysqld=mysqld_safe),--pid-file选项非常重要。每个 mysqld 应该有自己的进程 ID 文件。使用 mysqld_safe 而不是 mysqld 的优点在于,mysqld_safe 会监控其 mysqld 进程,并在该进程因使用kill -9发送信号或其他原因(例如段错误)终止时重新启动它。The--pid-fileoption 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. 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 usingkill -9or for other reasons, such as a segmentation fault.您可能想为 mysqld 使用
--user选项,但要做到这一点,您需要以 Unix 超级用户 (root) 身份运行 mysqld_multi 脚本。选项文件中的该选项无关紧要;如果您不是超级用户,并且 mysqld 进程在您自己的 Unix 账户下启动,您只会收到一个警告。You might want to use the--useroption for mysqld, but to do this you need to run the mysqld_multi script as the Unix superuser (root). 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_multi 使用。mysqld 程序启动或停止的顺序取决于它们在选项文件中出现的顺序。组号不必形成连续序列。在示例中故意省略了第一个和第五个 [mysqld 组,以说明选项文件中可以存在 “空隙”。这为您提供了更多的灵活性。The following example shows how you might set up an option file
for use with 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.
Group numbers need not form an unbroken sequence. The first and
fifth N][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]
# 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
参见 第 6.2.2.2 节,“使用选项文件”。See Section 6.2.2.2, “Using Option Files”.