之前有想过在一台服务器上运行多个MySQL实例就可以实现一从多主的master-slave方式的实时备份,今天刚好看到mysqld- multi就动手测试下
配置过程如下,
1. 修改mysql的配置文件my.cnf配置mysqld_multi的选项
[mysqld_multi]mysqld = /usr/local/mysql/bin/mysqld_safemysqladmin = /usr/local/mysql/bin/mysqladminuser = multi_adminpassword = multipasslog = /usr/local/mysql/etc/mysqld_multi.log2. 创建mysqld_multi的config-file
cat /usr/local/mysql/etc/mysqld_multi.cnf [mysqld1]socket = /tmp/mysql.sock1port = 3306pid-file = /usr/local/mysql/var1/localhost.piddatadir = /usr/local/mysql/var1user = mysql [mysqld2]socket = /tmp/mysql.sock2port = 3307pid-file = /usr/local/mysql/var2/localhost.piddatadir = /usr/local/mysql/var2user = mysql [mysqld3]socket = /tmp/mysql.sock3port = 3308pid-file = /usr/local/mysql/var3/localhost.piddatadir = /usr/local/mysql/var3user = mysql3. 拷贝mysqld_multi.server(在源代码的support-files中)脚本到/usr/sbin
cp /mysql_source/support-files/mysqld_multi.server /usr/sbin4. 编辑/usr/sbin/mysqld_multi.server(添加–config-file=/usr/local/mysql/etc /mysqld_multi.cnf选项)
'start' ) "$mysqld_multi" start $2 ;; 'stop' ) "$mysqld_multi" --config-file=/usr/local/mysql/etc/mysqld_multi.cnf stop $2 ;; 'report' ) "$mysqld_multi" --config-file=/usr/local/mysql/etc/mysqld_multi.cnf report $25. 启动多个MySQL实例
mysqld_multi.server start6. 之前在my.cnf设置的user和password是用来关闭数据库实例的,根据配置中的用户名和密码授权该用户shutdown权限
mysql -u root -S /tmp/mysql.sock1 -pmysql> grant shutdown on *.* to multi_admin@'localhost' identified by 'multipass';7. 关闭所有数据库实例
mysqld_multi.server stop8. 对单台数据库的启动和关闭
语法:mysqld_multi [options] {start|stop|report} [GNR[,GNR] …]
如对mysqld1的启动和关闭,可以通过mysqld_multi来操作
启动: mysqd_multi start 1
关闭: mysqd_multi stop 1
也可以同时启动和关闭多个数据库实例
启动: mysqd_multi start 1-3
关闭: mysqd_multi stop 1-3
参考:mysqld_multi — Manage Multiple MySQL Servers
本文转自 liang3391 51CTO博客,原文链接:http://blog.51cto.com/liang3391/456590