MySQL双主(主主)架构
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL双主(主主)架构相关的知识,希望对你有一定的参考价值。
128机器:
[[email protected] ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
129机器:
[[email protected] ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
先配主从:
128机器上:
拷贝数据并传输到129机器上
[[email protected] ~]# mysqldump -uroot -p123456 --all-databases > /tmp/mysqlall.sql [[email protected] ~]# 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机器上:
[[email protected] ~]# 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
[[email protected] ~]# /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双主(主主)架构的主要内容,如果未能解决你的问题,请参考以下文章