MySQL雙主(主主)架構
阿新 • • 發佈:2018-04-07
MySQL128機器:
[root@localhost ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
129機器:
[root@localhost ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
先配主從:
128機器上:
拷貝數據並傳輸到129機器上
[root@localhost ~]# mysqldump -uroot -p123456 --all-databases > /tmp/mysqlall.sql [root@localhost ~]# scp -r /tmp/mysqlall.sql 192.168.65.129:/tmp/
mysql> grant replication slave on *.* to 'repl'@192.168.65.129 identified by '123456'; mysql> flush privileges;
測試機器數據變化基本沒有,所以就不鎖表了
129機器上:
[root@localhost ~]# mysql -uroot -p123456 < /tmp/mysqlall.sql
mysql> stop slave; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_host='192.168.65.128', master_user='repl', master_password='123456', master_log_file='thermos.000001, master_log_pos=420; Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql> start slave; Query OK, 0 rows affected (0.01 sec) mysql> show slave status\G
主從同步完成
主主同步:
129機器上:
更改/etc/my.cnf,增加log_bin
[root@localhost ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
mysql> grant replication slave on *.* to 'repl'@192.168.65.128 identified by '123456'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec)
128機器上:
mysql> stop slave; Query OK, 0 rows affected (0.00 sec) mysql> change master to master_host='192.168.65.129', master_user='repl', master_password='123456', master_log_file='alex.000001', master_log_pos=420; Query OK, 0 rows affected, 2 warnings (0.01 sec) mysql> start slave; Query OK, 0 rows affected (0.00 sec) mysql> show slave status\G
測試主主
128上
129上
(已經多了micheal庫)
129上
128上
(多了jackson庫)
自己研究的,不知道正確與否,如果有錯誤,望指正!
MySQL雙主(主主)架構