1、AB复制
需要三台主机,IP分别为192.168.18.1、192.168.18.2和192.168.18.3
master;
vim /etc/my.cnf
server_id = 1
log-bin=binlog
log-bin-index=binlog.index
重启mysql
slave1:
vim /etc/my.cnf
server_id = 2
relay_log = /var/lib/mysql/mysql-relay-bin
relay_log_index=/var/lib/mysql/mysql-relay-bin.index
重启
master;
进入到mysql中,创建用户:
GRANT replication slave ON *.* TO 'dl'@'%' identified by '123';
GRANT replication slave ON *.* TO 'dl1'@'%' identified by '123';
flush privileges;
slave1:
将/etc/lib/mysql 下面的所有东西删除
重启mysql
master;
备份数据 到/tmp下面
mysqldump -A -x > /tmp/back.sql
再推送到B1主机上
scp /tmp/back.sql [email protected]:/tmp/
slave1:
导回数据
mysql < /tmp/full.sql
master;
mysql> flush tables with read lock;
将表给锁上,自己做实验时候可以省略这一步,生产环境下必须执行
mysql> show master status;
查看主状态
mysql> show master status;
+---------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+---------------+----------+--------------+------------------+
| binlog.000005 | 1039 | | |
+---------------+----------+--------------+------------------+
1 row in set (0.00 sec)
等slave1同步完成之后在将表解锁
mysql>unlock tables;
slave1:
mysql> change master to master_host='192.168.18.1', master_port=3306, master_user='dl', master_password='123', master_log_file='binlog.000005',master_log_pos=1039;
mysql> start slave;
mysql> show slave status\G
mysql> show slave status\G
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.18.1
Master_User: dl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000005
Read_Master_Log_Pos: 1039
Relay_Log_File: mysql-relay-bin.000004
Relay_Log_Pos: 316
Relay_Master_Log_File: binlog.000005
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
slave2;
vim /etc/my.cnf
server_id = 3
relay_log = /var/lib/mysql/mysql-relay-bin
relay_log_index=/var/lib/mysql/mysql-relay-bin.index
重启mysql
进入到mysql
mysql> change master to master_host='192.168.18.1', master_port=3306, master_user='dl1', master_password='123', master_log_file='binlog.000005',master_log_pos=1039;
mysql> start slave;