可以在RDS MySql Engine中进行Master-Master复制。但它需要一些实例的操纵。先决条件:1)创建两个实例的读取副本以启用二进位日志记录。2)如果不需要,删除它们两个的阅读副本。3)按照下面提到的主从设置说明进行操作。

在Master1上创建复制用户

grant replication slave on *.* to admin@% identified by admin;
Query OK, 0 rows affected (0.00 sec)

注意输出以下命令
show master status; + ---------------------------- + ---------- + --------- ----- + ------------------ + ------------------- + | 文件| 职位| Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | + ---------------------------- + ---------- + --------- ----- + ------------------ + ------------------- + | mysql-bin-changelog.000007 |120 | | | | + ---------------------------- + ---------- + --------- ----- + ------------------ + ------------------- + 1 row in set 0.00秒)在Master2上
mysql> call mysql.rds_set_external_master(master1.endpoint.amazonaws.com,3306,admin,admin,**mysql-bin-changelog.000007**,**120**,0);
Query OK, 0 rows affected (0.05 sec)

mysql> call mysql.rds_start_replication; +-------------------------+ | Message | +-------------------------+ | Slave running normally. | +-------------------------+ 1 row in set (1.01 sec)

mysql -u admin123 -padmin123 -h master2.endpoint.amazonaws.com -e "show slave statusG;" | grep Running
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
================================================== ====================

在Master2上

grant replication slave on *.* to admin@% identified by admin;
Query OK, 0 rows affected (0.00 sec)

show master status; +----------------------------+----------+--------------+------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +----------------------------+----------+--------------+------------------+-------------------+ | **mysql-bin-changelog.000007** | **120** | | | | +----------------------------+----------+--------------+------------------+-------------------+ 1 row in set (0.00 sec)

在Master1上

mysql> call mysql.rds_set_external_master(master2.endpoint.amazonaws.com,3306,admin,admin,**mysql-bin-changelog.000007**,**120**,0);
Query OK, 0 rows affected (0.05 sec)

mysql> call mysql.rds_start_replication; +-------------------------+ | Message | +-------------------------+ | Slave running normally. | +-------------------------+ 1 row in set (1.01 sec)

mysql -u admin123 -padmin123 -h master1.endpoint.amazonaws.com -e "show slave statusG;" | grep Running
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

分享改善这个答案

推荐阅读:

相关文章