mysqld_multi多实例

计划打算用主从来做同步备份,但是只有一台机,却要备份多个数据库,本来打算编译多一个mysql的,但是真的太麻烦了,所以抽时间研究了一下这个程序,感觉挻好用的,本文中mysql为手工编译,内容仅供参考。

1、先看看配置文件

[mysqld_multi]
mysqld     = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin


[mysqld1]
socket     = /tmp/mysql.sock1
port       = 3307
pid-file   = /usr/local/mysql/data2/hostname.pid1
datadir    = /usr/local/mysql/data2
#language   = /usr/local/mysql/share/mysql/english
user       = mysql
server-id = 1    
log-bin=mysql-bin.log  
binlog-do-db = test   
binlog-ignore-db=mysql  

[mysqld2]
socket     = /tmp/mysql.sock2
port       = 3308
pid-file   = /usr/local/mysql/data2/hostname.pid3
datadir    = /usr/local/mysql/data3
#language   = /usr/local/mysql/share/mysql/english
user       = mysql
server-id = 2  
log-bin = mysql-bin.log   
replicate-do-db = test  

上面配置了两个mysql实现,并计划用实例1做主,实例2做从 ,这样两个数据库同步。

2、创建目录内容

在shell执行

/usr/local/mysql>  ./scripts/mysql_install_db --datadir=./data2 --user=mysql
/usr/local/mysql> ./scripts/mysql_install_db --datadir=./data3 --user=mysql

3、查看,启动,关闭

./bin/mysqld_multi --defaults-file=./muti.cf report
./bin/mysqld_multi --defaults-file=./muti.cf start
./bin/mysqld_multi --defaults-file=./muti.cf stop

4、在主服务器

mysql -S /tmp/mysql.sock1
grant replication slave on *.* to 'replication'@'localhost' identified by '000000';  
flush privileges;

5、在从服务器执行

change master to master_host='localhost',master_port=3307, master_user='replication', master_password='000000', master_log_file='mysql-bin.000001', master_log_pos=107;  

上面是简单介绍,请参考

http://blog.csdn.net/yongzhang52545/article/details/7666545

http://chenzehe.iteye.com/blog/1266260