实验环境 rhel6.3
mysql-5.1.61-4.el6.x86_64
master 192.168.1.92
slave1 192.168.1.94
slave2 192.168.1.93
注意:在同步之前确保 master 与 slave 上的数据一致性。
一对多:如果写操作较少,而读操作很多时,可以采取这种结构。你可以将读操作分布到其它的 slave,从而减小
master 的压力。
master && slave1 && slave2都要安装mysql && mysql-server
#yum install -y mysql mysql-server
(1)master配置
#/etc/init.d/mysqld start
#vim /etc/my.cnf
server-id=1
log-bin=mysql.bin
binlog-do-db=test
#/etc/init.d/mysqld restart
创建同步账户,并且给予权限
mysql> grant replication slave, reload, super on *.* to username@'192.168.1.94' identified by 'password';
mysql> flush privileges;
mysql> show master status;
(2)slave1配置
#vim /etc/my.cnf
server-id=2
#/etc/init.d/mysqld start
mysql> change master to master_host='192.168.1.92', master_user='username', master_password='password', master_log_file='mysql-bin.000001', master_log_pos=106;
mysql> slave start;
mysql> show slave status\G;
Slave_IO_Running: Yes
Slave_SQL_Running: Yes ###如果都是 yes,表示从库的 I/O,Slave_SQL 线程都正确开启.表明数据库正在同步
线性操作:
(1)master
#mysqldump -predhat test > test.bak
#scp test.bak 192.168.1.93:
(2)slave2
# mysql -pyangqi test < test.bak
(3)slave1
#vim /etc/my.cnf
添加
slave1log-bin=mysql.bin
binlog-do-db=test
log-slave-updates
/etc/init.d/mysqld restart
(3)slave1
mysql> grant replication slave, reload, super on *.* to user@'192.168.1.93' identified by 'passwd';
mysql> flush privileges;
mysql> show master status;
(4)slave2
#vim /etc/my.cnf
server-id=3
#/etc/init.d/mysqld restart
(5)slave2
mysql> change master tp master_host='192.168.1.94', master_user='user', master_password='passwd', master_log_file='mysql-bin.000001', master_log_pos=106;
mysql> slave start;
mysql> show slave status\G;