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

MySQL 主主复制

时间:2015-02-18 21:02:20      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:

 

MySQL 主主复制搭建

 设置bin-log,并配置对方为自己的Master

 

1. 搭建

1.1 Master1配置为Master2的主

Master配置(my.cnf)

[mysqld]
server_id=1
log-bin=/usr/local/mysql-5.6.16/log/mysql-bin
skip-slave-start # 启动时不启动slave的复制进程
auto_increment_offset=0
auto_increment_increment=2
replicate-do-db=test
replicate-ignore-db=mysql

启动Master1

./bin/mysqld_safe --defaults-file=/usr/local/mysql-5.6.16/my.cnf --user=mysql &


创建用于复制的用户

mysql > grant replication slave on *.* to rep1‘@192.168.80.102‘ identified by rep1‘;


备份数据并还原到Master2服务器
-- 设置读锁,数据无法更新

mysql > flush tables with read lock;


-- 查看开始复制的位置

mysql > show master status;
+------------------+----------+--------------+------------------+-------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql-bin.000001 |      120 |              |                  |                   |
+------------------+----------+--------------+------------------+-------------------+


-- 传输数据

tar -czf - data/ | ssh 192.168.80.102 "tar -xzf - -C /usr/local/mysql-5.6.16"


-- 解除锁定

mysql > unlock tables;


Master2配置(my.cnf)

[mysqld]
server_id=2      # Master和Slave之间唯一
log-bin=/usr/local/mysql-5.6.16/log/mysql-bin
skip-slave-start # 启动时不启动slave的复制进程
auto_increment_offset=1
auto_increment_increment=2
replicate-do-db=test
replicate-ignore-db=mysql
 


启动Master2

./bin/mysqld_safe --defaults-file=/usr/local/mysql-5.6.16/my.cnf --user=mysql &


配置复制参数

mysql > change master to
    -> master_host=192.168.80.101,
    -> master_port=3306,
    -> master_user=rep1,
    -> master_password=rep1,
    -> master_log_file=mysql-bin.000001,
    -> master_log_pos=120;


启动Master2的IO和SQL线程

mysql > start slave;


检查

mysql > show processlist \G

应出现以下信息:
State: Waiting for master to send event
State: Slave has read all relay log; waiting for the slave I/O thread to update it

mysql > show slave status \G

应出现以下信息:
Slave_IO_State: Waiting for master to send event
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

1.2 Master2配置为Master1的主
对Master2执行show master status操作并对Master1执行change master to操作,检查。

 

MySQL 主主复制

标签:

原文地址:http://www.cnblogs.com/tjm-1990/p/4295922.html

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