aws rds复制ec2 mysql_AWS RDS之间如何建立复制

本文介绍了如何将本地MySQL数据库复制到AWS RDS,并从一个AWS RDS MySQL实例复制到另一个RDS实例。步骤包括设置binlog格式、创建复制用户、备份和恢复数据库、设置外部主库以及启动复制。检查`SHOW SLAVE STATUS`以验证复制是否正常工作。
摘要由CSDN通过智能技术生成

Jul 18, 2016

2 min

RDS is fully managed Database service by AWS . Mysql is also available there. Relica - It is necessary to everyone for Backup the data, DR, Testing,etc. AWS also provide the Read replica option. Recently they launched cross region replica for Mysql and Postgresql. We are helping to you Replicate your On-prem MySQL database to RDS and replicate RDS to On-prem servers. Now we’ll guide you to replicate MySQL RDS to RDS. You can replicate it to any region.

Pre-requisites:

Both RDS instances are publically available.

They must have same Parameter group values.

MySQL version - MySQL supports replication from one release series to the next higher release series. (Ex. you can replicate 5.5 to 5.6, you can’t replicate 5.5 to 5.7)

Both RDS have the same Parameter group values and Same optional group values

Steps1: Set binlog format

Change Master and slave binlog_format to ROW.(It’ll skip some initial errors)

Step2: Create user for replication and grant replication privilege.

I have created an user called repl_user and its password repl_user.

CREATE USER 'rep_user'@'%' IDENTIFIED BY 'rep_user'; GRANT REPLICATION slave ON *.* TO 'rep_user'@'%' IDENTIFIED BY 'rep_user';

FLUSH PRIVILEGES;

0818b9ca8b590ca3270a3433284dd417.png

Step3: Create a table and insert some rows.

Use PowerupDBA;

Create table rep_test (number int);

Insert into rep_test values (1);

Insert into rep_test values (2);

Insert into rep_test values (3);

0818b9ca8b590ca3270a3433284dd417.png

Step4: Note the master binlog position.

Show master status;

0818b9ca8b590ca3270a3433284dd417.png

Step5: Backup the all Master databases.

Copy the database from the external instance to the Amazon RDS DB instance using mysqldump.

mysqldump --single-transaction --routines --triggers --events --databases PowerupDBA -h ******.ciqk2zkqxh3j.us-east-1.rds.amazonaws.com -u powerupdba -p > Powerupdba_bak.sql

0818b9ca8b590ca3270a3433284dd417.png

Step6: Restore the backup file to Slave.

mysql -h ****.ciqk2zkqxh3j.us-east-1.rds.amazonaws.com -u Powerupdba -p PowerupDBA < Powerupdba_bak.sql

0818b9ca8b590ca3270a3433284dd417.png

Step7: Mention master server and replication user on Slave.

Connect to the Slave Amazon RDS DB instance as the master user and identify the external MySQL or MariaDB database as the replication master by using the mysql.rdssetexternal_master command.

CALL mysql.rds_set_external_master ('Master_RDS_EndPoint', 3306, 'Replication_user_name', 'Replication_User_password', 'BinLog_FileName', BingLog_Position, 0);

Step8: Start Replication

On the Amazon RDS DB instance, issue the mysql.rdsstartreplication command to start replication

CALL mysql.rds_start_replication;

0818b9ca8b590ca3270a3433284dd417.png

Step9: Check replication;

Show slave status will show the replication is working or not.

Show slave status\G;

0818b9ca8b590ca3270a3433284dd417.pngI have inserted 3 more rows.

Insert into rep_test values (4);

Insert into rep_test values (5);

Insert into rep_test values (6);

0818b9ca8b590ca3270a3433284dd417.pngNow check this slave.

select * from rep_test;

0818b9ca8b590ca3270a3433284dd417.png

Yup, its replicated :)

转载自:http://blog.powerupcloud.com/2016/07/18/how-to-configure-replication-between-aws-mysql-rds-to-mysql-rds/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值