1.mysqld_multi介绍
mysqld_multi can be used to start, reload, or stop any number of separate mysqld processes running in different TCP/IP ports and UNIX sockets.
mysqld_multi可用于启动,重新加载或停止在不同的TCP / IP端口和UNIX套接字中运行的任意数量的独立mysqld进程。
2.mysqld_multi用法和注意事项
2.1创建专用用户
mysqld服务的MySQL用户对mysqld_multi访问的所有MySQL服务器具有相同的密码。
建议您为由mysqld_multi控制的所有MySQL服务器创建一个通用的“ multi_admin”用户,此用户对mysqld_multi访问的所有MySQL服务器具有相同的密码。该用户需要具有'Shutdown_priv'-特权,出于安全原因,不应具有其他特权。示例:
GRANT SHUTDOWN ON *.* TO multi_admin@localhost IDENTIFIED BY 'password'
2.2PID文件
如果使用mysqld_safe启动mysqld,请确保每个MySQL服务器都有一个单独的pid文件。 为了通过mysqld_multi使用mysqld_safe,您需要使用两个选项:
mysqld=/path/to/mysqld_safe
ledir=/path/to/mysqld-binary/
ledir (library executable directory), 是仅mysqld_safe接受的选项,如果尝试将其直接传递给mysqld,则会收到错误消息。 因此,最好直接在[mysqld#]组中使用上述选项。
2.3.DATA DIRECTORY
不建议在同一数据目录中运行许多MySQL服务器。 这样做将最终导致不良结果。
- Speed penalty
速度惩罚 - Risk of table/data corruption
表/数据损坏的风险 - Data synchronising problems between the running servers
正在运行的服务器之间的数据同步问题 - Heavily media (disk) bound
大量介质(磁盘)绑定 - Relies on the system (external) file locking
依靠系统(外部)文件锁定 - Is not applicable with all table types. (Such as InnoDB)
不适用于所有表格类型。 (例如InnoDB)
2.4.TCP/IP Port
Every server requires one and it must be unique.每个服务器都需要一个,并且必须唯一。
2.5.[mysqld#] Groups
在配置文件中,mysqld group之间有间隔。如实例配置文件中所示,[mysqld1]和[mysqld5]没有配置。
2.6.MySQL Server User
您可以在[mysqld#]组内传递user = ...选项。 在某些情况下,这可能非常方便,但是随后您需要以UNIX root用户身份运行mysqld_multi。
2.7.A Start-up Manage Script for mysqld_multi
在support-files 目录中有一个名为mysqld_multi.server.sh的文件,可以启动和停止多台服务器。您可以将文件放在/etc/init.d/mysqld_multi.server.sh中,并在各种运行级别(根据Linux / Unix标准)建立所需的符号链接。 也可以用/etc/init.d/mysql.server脚本替换它。
在使用之前,必须在my.cnf文件,并添加[mysqld_multi]和[mysqld#]组。
mysqld_multi配置示例:
[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
support-files/mysqld_multi.server
#!/bin/sh
#
# A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.
# This script assumes that my.cnf file exists either in /etc/my.cnf or
# /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the
# mysqld_multi documentation for detailed instructions.
#
# This script can be used as /etc/init.d/mysql.server
#
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
#
# Version 1.0
#
basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin
if test -x $bindir/mysqld_multi
then
mysqld_multi="$bindir/mysqld_multi";
else
echo "Can't execute $bindir/mysqld_multi from dir $basedir";
exit;
fi
case "$1" in
'start' )
"$mysqld_multi" start $2
;;
'stop' )
"$mysqld_multi" stop $2
;;
'report' )
"$mysqld_multi" report $2
;;
'restart' )
"$mysqld_multi" stop $2
"$mysqld_multi" start $2
;;
*)
echo "Usage: $0 {start|stop|report|restart}" >&2
;;
esac