🔗Setup AWS MySQL RDS instance as slave of an external master

Configure external mysql to become master:

binlog-format= mixed

Setup the master replica user:

mysql> create user `replica`@`%` identified by 'PASSWORD';
mysql> grant replication slave on *.* to 'replica'@'%';

Use the following command to ensure that nothing can write to the master database during a database dump. Also note the filename and position of the binary log because you will need these values to complete the replication configuration:

mysql> show master status;
| File              | Position  | Binlog_Do_DB | Binlog_Ignore_DB                                 |
| mysqld-bin.000205 | 207450664 | epazote      | test,information_schema,performance_schema,mysql |
1 row in set (0.00 sec)

If this is a replica do this:

mysql> show slave status\G

And look for:

Master_Log_File: mysql-bin-changelog.023713
Read_Master_Log_Pos: 1934704

Within AWS RDS you can also do:

mysql> call mysql.rds_stop_replication;
mysql> show slave status\G

Take a dump:

mysqldump -h host.tld --user='user' --password='secret' --add-drop-database --compress --hex-blob --opt --skip-comments --skip-lock-tables --single-transaction db_name > out.sql

to dump all databases use --all-databases

To get the the log position this can be used:



mysqldump -h host.tld --master-data=1 --compress --hex-blob --opt --skip-comments --skip-lock-tables --single-transaction db_name -u user -p > out.sql

Then, lift the read lock from the master:


or within AWS use:

mysql> call mysql.rds_start_replication;

If you get a Last_IO_Error: Got fatal error 1236..., if you can afford it, don't unlock/start the replication after having the dump

Load the dump:

mysql --compress -h host.tld -u user database < out.sql

--compress seems to improve the speed

After loading a full dump to RDS, Call the stored procedure mysql.rds_set_external_master like this:

mysql> call mysql.rds_set_external_master ('servername', port, 'user', 'password', 'binlog-file', binlog-offset, 0);


mysql> call mysql.rds_set_external_master ('', 3306, 'replica', 'password', 'mysql-bin-changelog.122', 108433, 0);

Then start the replication by doing:

mysql> call mysql.rds_start_replication;

Check if slave is running:

mysql> show slave status;

🔗Promote RDS to master

This will promote the slave to become master:

mysql> call mysql.rds_stop_replication;
mysql> call mysql.rds_reset_external_master;


In Amazon RDS, The default value of binlog retention hours is NULL (do not retain binary logs), to keep logs for 7 days use:

call mysql.rds_set_configuration('binlog retention hours', 168);

This could help to prevent getting the error:

Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file', Error_code: 1236