參考 mysql搭建安裝完mysql後
https://blog.51cto.com/popli3/2357211
服務器A | 服務器B |
---|---|
192.168.0.104 | 192.168.0.105 |
在服務器A(192.168.0.104)上:
- 打開log-bin和server-id=1選項
[root@minion-2 ~]# vi /etc/my.cnf
log-bin
server-id=1 - 授權賬戶並重啓
mysql> grant super,reload,replication slave on *.* to [email protected] identified by 'slave';
mysql> flush privileges;
mysql>quit
[root@minion-2 ~]# service mysqld restart
在服務器B(192.168.0.105)上:
- 打開server-id=2和log-bin
[root@minion-2 ~]# vi /etc/my.cnf
log-bin
server-id=2 - 開啓change master 功能,這邊的host是你主的地址,user和pass都是上一步grant設置的
mysql>change master to master_host='192.168.0.104',master_user='slave',master_password='slave';
mysql> start slave;
至此單向的主從完畢,接下來是反過來操作一遍
在服務器B(192.168.0.105)上:
mysql> grant super,reload,replication slave on *.* to [email protected] identified by 'slave';
mysql> flush privileges;
在服務器A(192.168.0.104)上:
mysql>change master to master_host='192.168.0.105',master_user='slave',master_password='slave';
mysql> start slave;