Chinaunix首页 | 论坛 | 博客
  • 博客访问: 246447
  • 博文数量: 79
  • 博客积分: 1942
  • 博客等级: 上尉
  • 技术积分: 910
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-19 16:17
文章分类

全部博文(79)

文章存档

2011年(1)

2010年(50)

2009年(28)

分类: LINUX

2010-04-26 21:53:26

之前有想过在一台服务器上运行多个MySQL实例就可以实现一从多主的master-slave方式的实时备份,今天刚好看到mysqld- multi就动手测试下

配置过程如下,
1. 修改mysql的配置文件my.cnf配置mysqld_multi的选项

[mysqld_multi]
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
user = multi_admin
password = multipass
log = /usr/local/mysql/etc/mysqld_multi.log

2. 创建mysqld_multi的config-file

cat /usr/local/mysql/etc/mysqld_multi.cnf 
[mysqld1]
socket = /tmp/mysql.sock1
port = 3306
pid-file = /usr/local/mysql/var1/localhost.pid
datadir = /usr/local/mysql/var1
user = mysql
 
[mysqld2]
socket = /tmp/mysql.sock2
port = 3307
pid-file = /usr/local/mysql/var2/localhost.pid
datadir = /usr/local/mysql/var2
user = mysql
 
[mysqld3]
socket = /tmp/mysql.sock3
port = 3308
pid-file = /usr/local/mysql/var3/localhost.pid
datadir = /usr/local/mysql/var3
user = mysql

3. 拷贝mysqld_multi.server(在源代码的support-files中)脚本到/usr/sbin

cp /mysql_source/support-files/mysqld_multi.server /usr/sbin

4. 编辑/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 $2

5. 启动多个MySQL实例

mysqld_multi.server start

6. 之前在my.cnf设置的user和password是用来关闭数据库实例的,根据配置中的用户名和密码授权该用户shutdown权限

mysql -u root -S /tmp/mysql.sock1 -p
mysql> grant shutdown on *.* to multi_admin@'localhost' identified by 'multipass';

7. 关闭所有数据库实例

mysqld_multi.server stop

8. 对单台数据库的启动和关闭
语法: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

阅读(1055) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:备份脚本

给主人留下些什么吧!~~