mysql同步复制模式_mysql同步复制M-M(master master)模式

转:题记:关于mysql 同步复制技术的文章,M-S方式的非常多,本篇是我做的M-M模式的测试记录:

一。前期准备

机器A:ip地址 192.168.1.210 (maste1)

机器B:ip地址  192.168.1.211  (master2)

机器A同时充当Slave角色,为便于区分,名称设为 Slave2

机器B同时充当Slave角色,为便于区分,名称设为 Slave1

假设两台机器都已经安装好mysql,安装路径假设/usr/local/mysql/下,并假设

mysql配置文件my.cnf存放在/etc/下

二。修改机器A中mysql配置文件/etc/my.cnf

在[mysqld]配置段添加如下字段

引用

binlog-do-db= wywdb       # 指明欲同步数据库

binlog-ignore-db=mysql    #  指明不需要同步数据库

binlog-ignore-db=test      # 指明不需要同步数据库

并假设次server id 为1,即

server-id=1

在机器A,即master1上为机器B,即slave1添加一同步帐号

引用

grant replication slave on *.* to ‘replication’@192.168.1.211 identified by ’slave’;

然后重启A机器mysql

三。修改B机器中mysql配置文件

同样在[mysqld]字段下添加如下内容

引用

server-id=2

master-host = 192.168.1.210

master-user = replication

master-password = slave

master-port = 3306

然后重启B机器mysql

四。在B中进入mysql

引用

mysql> start slave;

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.1.210

Master_User: replication

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000003

Read_Master_Log_Pos: 98

Relay_Log_File: webserver-relay-bin.000004

Relay_Log_Pos: 235

Relay_Master_Log_File: mysql-bin.000003

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 98

Relay_Log_Space: 235

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

1 row in set (0.00 sec)

ERROR:

No query specified

将显示以上同步信息,其中Slave_IO_Running和Slave_SQL_Running对应字段内容都为yes,

并且Slave_IO_State显示“Waiting for master to send event”,则表示mysql的Master和Slave

模式配置成功,否则表示不成功,可查看相应日志,查看什么地方出现了问题。

此时还可可进去A机器中查看master1的mysql同步信息,并可与B机器mysql对比。

在A机器中进入mysql:

引用

mysql> show master status;

+——————+———-+————–+——————+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+——————+———-+————–+——————+

| mysql-bin.000003 |       98 | wywdb        | mysql,test       |

+——————+———-+————–+——————+

1 row in set (0.00 sec)

五。在机器B中为其增加一同步复制帐号

mysql> grant replication slave on *.* to ‘replication’@192.168.1.210 identified by ’slave2′;

并修改A中mysql的配置文件

在[mysqld]增加如下内容

master-host = 192.168.1.211

master-user = replication

master-password = slave2

master-port = 3306

六。依次重启A和B中mysql

进A中mysql

mysql> start slave;

然后可以查看同步情况

进入A中:

引用

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.1.211

Master_User: replication

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000004

Read_Master_Log_Pos: 98

Relay_Log_File: centos-relay-bin.000005

Relay_Log_Pos: 235

Relay_Master_Log_File: mysql-bin.000004

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 98

Relay_Log_Space: 235

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

1 row in set (0.00 sec)

ERROR:

No query specified

mysql> show master status;

+——————+———-+————–+——————+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+——————+———-+————–+——————+

| mysql-bin.000004 |       98 | wywdb        | mysql,test       |

+——————+———-+————–+——————+

1 row in set (0.00 sec)

在B中:

mysql> show slave status\G;

*************************** 1. row ***************************

Slave_IO_State: Waiting for master to send event

Master_Host: 192.168.1.210

Master_User: replication

Master_Port: 3306

Connect_Retry: 60

Master_Log_File: mysql-bin.000004

Read_Master_Log_Pos: 98

Relay_Log_File: webserver-relay-bin.000007

Relay_Log_Pos: 235

Relay_Master_Log_File: mysql-bin.000004

Slave_IO_Running: Yes

Slave_SQL_Running: Yes

Replicate_Do_DB:

Replicate_Ignore_DB:

Replicate_Do_Table:

Replicate_Ignore_Table:

Replicate_Wild_Do_Table:

Replicate_Wild_Ignore_Table:

Last_Errno: 0

Last_Error:

Skip_Counter: 0

Exec_Master_Log_Pos: 98

Relay_Log_Space: 235

Until_Condition: None

Until_Log_File:

Until_Log_Pos: 0

Master_SSL_Allowed: No

Master_SSL_CA_File:

Master_SSL_CA_Path:

Master_SSL_Cert:

Master_SSL_Cipher:

Master_SSL_Key:

Seconds_Behind_Master: 0

1 row in set (0.00 sec)

ERROR:

No query specified

引用

mysql> show master status;

+——————+———-+————–+——————+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+——————+———-+————–+——————+

| mysql-bin.000004 |       98 | wywdb        |                  |

+——————+———-+————–+——————+

1 row in set (0.00 sec)

看到如上信息证明mysql的master和master模式同步配置成功。

七。简单同步验证测试

在A中

引用

mysql> use wywdb

Database changed

mysql> create table test(id int,name varchar(20));

Query OK, 0 rows affected (0.03 sec)

mysql> insert into test values(1,’wanzhihua’);

Query OK, 1 row affected (0.00 sec)

mysql> select * from test;

+——+———–+

| id   | name      |

+——+———–+

|    1 | wanzhihua |

+——+———–+

1 row in set (0.01 sec)

然后进入B中

引用

mysql> use wywdb

Database changed

mysql> select * from test;

+——+———–+

| id   | name      |

+——+———–+

|    1 | wanzhihua |

+——+———–+

1 row in set (0.00 sec)

证明A--->B同步成功

接着

mysql> insert into test values (2, ’shenyanfei’);

Query OK, 1 row affected (0.00 sec)

mysql> select * from test;

+——+————+

| id   | name       |

+——+————+

|    1 | wanzhihua  |

|    2 | shenyanfei |

+——+————+

2 rows in set (0.01 sec)

然后进去A中

引用

mysql> select * from test;

+——+————+

| id   | name       |

+——+————+

|    1 | wanzhihua  |

|    2 | shenyanfei |

+——+————+

2 rows in set (0.00 sec)证明AB互为同步成功。

后继:本文只是安装过程,对自增长,存储引擎,索引等没有详加阐述

,如需要,则需根据自身实际情况在次基础上作些修改。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值