作者:经任萍 | 来源:互联网 | 2023-07-27 11:04
是的,可以在RDSMySqlEngine中进行Master-Master复制。但它需要一些操作与实例。先决条件:1)为启用二进制日志记录创建两个实例的只读副本。2)如果不需要,删除
是的,可以在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 server 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 status\G;" | 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 status\G;" | 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