文章翻译:miFor
信息来源:mifor.4dian.org
今天看了看MySQL的Manual,看到了这个mysqld_multi,对这个有点兴趣,所有就翻译了一下。水平有限,只要能看懂就好啦~~~~:)
mysqld_multi是管理多个mysqld的服务进程,这些服务进程程序不同的unix socket或是监听于不同的端口。他可以启动、停止和监控当前的服务状态。
程序在my.cnf(或是在--config-file自定义的配置文件)中搜索[mysqld#]段,"#"可以是任意的正整数。这个正整数就是在下面提及的段序列,即GNR。段的序号做为mysqld_multi的参数,来区别不同的段,这样你就可以控制特定mysqld进程的启动、停止或得到他的报告信息。这些组里的参数就像启动一个mysqld所需要的组的参数一样。但是,如果使用多服务,必须为每个服务指定一个unix socket或端口。
使用如下参数来启动mysqld_multi:
shell> mysqld_multi [options] {start|stop|report} [GNR[,GNR]...]
start,stop和report是指你想到执行的操作。你可以在单独的服务或是多服务上指定一个操作,区别于选项后面的GNR列表。如果没有指定GNR列表,那么mysqld_multi将在所有的服务中根据选项文件进行操作。
每一个GNR的值是组的序列号或是一个组的序列号范围。此项的值必须是组名字最后的数字,比如说如果组名为mysqld17,那么此项的值则为17.如果指定一个范围,使用"-"(破折号)来连接二个数字。如GNR的值为10-13,则指组mysqld10到组mysqld13。多个组或是组范围可以在命令行中指定,使用","(逗号)隔开。不能有空白的字符(如空格或tab),在空白字符后面的参数将会被忽略。
启动特定的组mysqld17
shell> mysqld_multi start 17
启动一些组,mysqld8和mysqld10到mysqld13
shell> mysqld_multi start 8,10-13
得到关于option设置的示范帮助
shell> mysqld_multi --example
--config-file=name
指定自己的配置文件,也是mysqld_multi在启动时所搜索mysqld#时用到的文件,如果不设置此选项的话,mysqld_multi将会读取自己的配置文件,通常是my.cnf里搜索mysqld#。
--example
不用翻译了吧
--help
不用翻译了TOO
--log=name
指定日志文件,如果文件存在,则以追加方式记录。
--mysqladmin=prog_name
用于停止服务的mysqladmin程序
--mysqld=prog_name
mysqld的程序。你也可以指定一个mysqld_safe做为此项的值,他将自动指向到mysqld。确认你的mysqld路径,或是在PATH环境变量里可以找到他。
--no-log
把日志输出到标准输出,而不是到日志文件,默认的是写到日志文件。
--password=password
调用mysqladmin时,使用的MySQL用户帐号的密码。
--tcp-ip
使用tcp/ip端来代替unix socket文件。(如果unix socket文件丢失,服务也可以运行,但是只能通过tcp/ip端口连接),默认的,连接将通过UNIX SOCKET文件,此选项影响停止停止和报告操作。
--user=user_name
使用mysqladmin时所使用的MySQL的用户名
--version
列出版本信息然后退出。
关于mysqld_multi的一些注意事项
1、当使用mysqladmin程序来停止mysqld服务时,确保每一个mysqld有相当的用户名和密码,当然也要有关闭的权限。如果你管理的服务器上有很多不同的用户名和密码,你就要为每一个mysqld设置一个相同的用户名和密码,使用如下命令:
shell> mysql -u root -S /tmp/mysql.sock -proot_password
mysql> GRANT SHUTDOWN ON *.*
-> TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
参考How the Privilege System Works。要为每一个mysqld都设置一下。而且要保证此用户可以用multi_admin连接(主机和用户)。
2、如果你使用mysqld_safe来启动mysqld的话(如--mysqld=mysqld_safe),那么--pid-file就很重要了。每一个msyqld都要有自己的Pid文件。使用mysqld_safe代替mysqld来启动的好处是mysqld_safe"保护"自己的mysqld进程,当进程收到kill -9的信号,或是其他原因,如内存溢出,那么mysqld进程会被重新启动。确认mysqld_safe脚本需要在一个确定的目录进行启动。也就是说,在启动mysqld_multi前,要把mysqld_safe移动到一个确定的目录。如果启动有问题的话,检查一下mysqld_safe的如下行:
----------------------------------------------------------------
MY_PWD=`pwd`
# Check if we are starting this relative (for the binary release)
if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
-x ./bin/mysqld
----------------------------------------------------------------
3、每一个mysqld都要有自己的unix socket文件和tcp/ip监听端口。
4、在启动mysqld的时候你应该会使用--user选项,但是在启动mysqld_multi脚本的时候,你要使用root用户。在配置中使用这个配置是没有关系的,如果你使用普通用户启动的话,那么你将只能启动属于自己用户的mysqld,并且得到一个警告(warning)。
5、重要:确认每一个启动mysqld进程的用户有对其数据目录的完全访问权限。不要使用root帐号,除非你知道自己在干什么。
6、非常重要:在使用mysqld_multi前,你要理解mysqld的配置和为什么要将mysqld进行分离。小心多个mysqld进程使用一个数据目录的危险,除非你自己知道在做什么。在一个线程系统中启动多个mysqld去操作同一个数据目录不会给你带来额外的性能。参考Running Multiple MySQL Servers on the Same Machine.
下面是使用mysqld_multi时所需要设置的配置文件的例子。前五段[mysqld#]是举例说话说明,适合人们的口。mysqld启动或停止取决于在配置文件中的命令。
# This file should probably be in your home dir (~/.my.cnf)
# or /etc/my.cnf
# Version 2.1 by Jani Tolonen
[mysqld_multi]
mysqld = /usr/local/bin/mysqld_safe
mysqladmin = /usr/local/bin/mysqladmin
user = multi_admin
password = multipass
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /usr/local/mysql/var2/hostname.pid2
datadir = /usr/local/mysql/var2
language = /usr/local/share/mysql/english
user = john
[mysqld3]
socket = /tmp/mysql.sock3
port = 3308
pid-file = /usr/local/mysql/var3/hostname.pid3
datadir = /usr/local/mysql/var3
language = /usr/local/share/mysql/swedish
user = monty
[mysqld4]
socket = /tmp/mysql.sock4
port = 3309
pid-file = /usr/local/mysql/var4/hostname.pid4
datadir = /usr/local/mysql/var4
language = /usr/local/share/mysql/estonia
user = tonu
[mysqld6]
socket = /tmp/mysql.sock6
port = 3311
pid-file = /usr/local/mysql/var6/hostname.pid6
datadir = /usr/local/mysql/var6
language = /usr/local/share/mysql/japanese
user = jani
参考Using Option Files。
以下是原文:
5.1.5 The mysqld_multi Program for Managing Multiple MySQL Servers
mysqld_multi is meant for managing 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.
The program searches for groups named [mysqld#] in `my.cnf' (or in the file named by the --config-file option). # 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.4.2.2 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 5.10 Running Multiple MySQL Servers on the Same Machine.
To invoke mysqld_multi, use the following syntax:
shell> mysqld_multi [options] {start|stop|report} [GNR[,GNR]...]
start, stop, and report indicate which operation you want to perform. You can perform the designated operation on 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.
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.
This command starts a single server using option group [mysqld17]:
shell> mysqld_multi start 17
This command stops several servers, using option groups [mysql8] and [mysqld10] through [mysqld13]:
shell> mysqld_multi start 8,10-13
For an example of how you might set up an option file, use this command:
shell> mysqld_multi --example
mysqld_multi supports the following options:
--config-file=name
Specify the name of an alternative option file. This affects where mysqld_multi looks for [mysqld#] option groups. Without this option, all options are read from the usual `my.cnf' file. The option does not affect where mysqld_multi reads its own options, which are always taken from the [mysqld_multi] group in the usual `my.cnf' file.
--example
Display a sample option file.
--help
Display a help message and exit.
--log=name
Specify the name of the log file. If the file exists, log output is appended to it.
--mysqladmin=prog_name
The mysqladmin binary to be used to stop servers.
--mysqld=prog_name
The mysqld binary to be used. Note that you can specify mysqld_safe as the value for this option also. The options are passed to mysqld. Just make sure that you have the directory where mysqld is located in your PATH environment variable setting or fix mysqld_safe.
--no-log
Print log information to stdout rather than to the log file. By default, output goes to the log file.
--password=password
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.
--tcp-ip
Connect to each MySQL server via 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 via the TCP/IP port.) By default, connections are made using the Unix socket file. This option affects stop and report operations.
--user=user_name
The username of the MySQL account to use when invoking mysqladmin.
--version
Display version information and exit.
Some notes about mysqld_multi:
Make sure that the MySQL account used for stopping the mysqld servers (with the mysqladmin program) has the same username and password for each server. Also, make sure that the account has the SHUTDOWN privilege. If the servers that you want to manage have many different usernames or passwords for the administrative accounts, you might want to create an account on each server that has the same username and password. For example, you might set up a common multi_admin account by executing the following commands for each server:
shell> mysql -u root -S /tmp/mysql.sock -proot_password
mysql> GRANT SHUTDOWN ON *.*
-> TO 'multi_admin'@'localhost' IDENTIFIED BY 'multipass';
See section 5.5.2 How the Privilege System Works. You will have to do this for each mysqld server. Change the connection parameters appropriately when connecting to each one. Note that the host part of the account name must allow you to connect as multi_admin from the host where you want to run mysqld_multi.
The --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. The advantage of using mysqld_safe instead of mysqld is that mysqld_safe ``guards'' its mysqld process and will restart it if the process terminates due to a signal sent using kill -9, or for other reasons, such as a segmentation fault. Please note that the mysqld_safe script might require that you start it from a certain place. This means that you might have to change location to a certain directory before running mysqld_multi. If you have problems starting, please see the mysqld_safe script. Check especially the lines:
----------------------------------------------------------------
MY_PWD=`pwd`
# Check if we are starting this relative (for the binary release)
if test -d $MY_PWD/data/mysql -a -f ./share/mysql/english/errmsg.sys -a \
-x ./bin/mysqld
----------------------------------------------------------------
See section 5.1.3 The mysqld_safe Server Startup Script. The test performed by these lines should be successful, or you might encounter problems.
The Unix socket file and the TCP/IP port number must be different for every mysqld.
You might want to use the --user option for mysqld, but in order to do this you need to run the mysqld_multi script as the Unix root user. Having the option in the option file doesn't matter; you will just get a warning, if you are not the superuser and the mysqld processes are started under your own Unix account.
Important: Make sure that the data directory is fully accessible to the Unix account that the specific mysqld process is started as. Do not use the Unix root account for this, unless you know what you are doing.
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 will not give you extra performance in a threaded system. See section 5.10 Running Multiple MySQL Servers on the Same Machine.
The following example shows how you might set up an option file for use with mysqld_multi. The first and fifth [mysqld#] group were intentionally left out from the example to illustrate that you can have ``gaps'' in the option file. This gives you more flexibility. The order in which the mysqld programs are started or stopped depends on the order in which they appear in the option file.
# This file should probably be in your home dir (~/.my.cnf)
# or /etc/my.cnf
# Version 2.1 by Jani Tolonen
[mysqld_multi]
mysqld = /usr/local/bin/mysqld_safe
mysqladmin = /usr/local/bin/mysqladmin
user = multi_admin
password = multipass
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /usr/local/mysql/var2/hostname.pid2
datadir = /usr/local/mysql/var2
language = /usr/local/share/mysql/english
user = john
[mysqld3]
socket = /tmp/mysql.sock3
port = 3308
pid-file = /usr/local/mysql/var3/hostname.pid3
datadir = /usr/local/mysql/var3
language = /usr/local/share/mysql/swedish
user = monty
[mysqld4]
socket = /tmp/mysql.sock4
port = 3309
pid-file = /usr/local/mysql/var4/hostname.pid4
datadir = /usr/local/mysql/var4
language = /usr/local/share/mysql/estonia
user = tonu
[mysqld6]
socket = /tmp/mysql.sock6
port = 3311
pid-file = /usr/local/mysql/var6/hostname.pid6
datadir = /usr/local/mysql/var6
language = /usr/local/share/mysql/japanese
user = jani
See section 4.3.2 Using Option Files.