码迷,mamicode.com
首页 > 数据库 > 详细

mysql主主备份

时间:2015-11-05 16:48:37      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:mysql 主主复制

mysql主主配置和主从配置的不同点在于主从的master不监控slavebin-log的变化,导致slave有新数据不能更新到master

主主配置的关键参数:log-slave-updates,两台mysql都需添加


测试环境:

centos 6.5 x64

主1ip:192.168.0.1

主2ip:192.168.0.2


主主配置

主1

vim /etc/my.cnf

server-id=1

bin-log=mysql-bin

binlog-format=mixed

log-slave-updates

relay-log=mysql-relay

主2

server-id=2

bin-log=mysql-bin

binlog-format=mixed

log-slave-updates

relay-log=mysql-relay

修改配置后均重启mysql使配置生效

分别在主1和主2上做主从

一、给主1配置从

在主1上

1.授权登陆账号(两边要建立可复制的账号)

grant replication client,replication slave on *.* to ‘salve‘@‘192.168.0.*‘ identified by ‘test123‘;

2.show master status;

mysql> show master status;

+------------------+----------+--------------+------------------+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+------------------+----------+--------------+------------------+

| mysql-bin.000002 |      653 |              |                  |

+------------------+----------+--------------+------------------+

1 row in set (0.00 sec)

在主2上

stop slave;

reset slave;

change master to master_host=‘192.168.0.1‘,master_user=‘slave‘,master_password=‘test123‘,master_log_file=‘mysql-bin.000002‘,master_log_pos=653;

start slave;

show salve status\G;

 Slave_IO_Running: Yes

 Slave_SQL_Running: Yes

即成功

一、给主2配置从

步骤通给主1配置从


测试:

分别在主1和主2添加数据,看在另一台是否能查询

在主1上

mysql> select * from t;

+---+

| s |

+---+

| 2 |

+---+

1 row in set (0.00 sec)


mysql> insert into t values (3);

Query OK, 1 row affected (0.01 sec)


mysql> select * from t;         

+---+

| s |

+---+

| 2 |

| 3 |

+---+

2 rows in set (0.00 sec)


mysql> select * from t;

+---+

| s |

+---+

| 2 |

| 3 |

| 4 |

+---+

3 rows in set (0.00 sec)

在主2上

mysql> use proxy_test;

Database changed

mysql> select * from t;

+---+

| s |

+---+

| 2 |

+---+

1 row in set (0.00 sec)


mysql> select * from t;

+---+

| s |

+---+

| 2 |

| 3 |

+---+

2 rows in set (0.00 sec)


mysql> insert into t values (4);

Query OK, 1 row affected (0.00 sec)


mysql> select * from t;         

+---+

| s |

+---+

| 2 |

| 3 |

| 4 |

+---+

3 rows in set (0.00 sec)


主主配置到此测试成功


mysql主主备份

标签:mysql 主主复制

原文地址:http://j99d99.blog.51cto.com/2828759/1709927

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!