{"id":1938,"date":"2014-05-30T05:13:18","date_gmt":"2014-05-30T05:13:18","guid":{"rendered":"http:\/\/blog.cloudthat.com\/?p=1938"},"modified":"2024-06-25T11:14:19","modified_gmt":"2024-06-25T11:14:19","slug":"mysql-data-migration-capabilities-for-rds","status":"publish","type":"blog","link":"https:\/\/www.cloudthat.com\/resources\/blog\/mysql-data-migration-capabilities-for-rds","title":{"rendered":"MYSQL Data Migration Capabilities for RDS"},"content":{"rendered":"<p>RDS now has a provision to set a non RDS mysql instance (on premise or EC2) as its master and vice-versa.<\/p>\n<p>To test this out<\/p>\n<ol>\n<li>Start up an RDS instance.<\/li>\n<li>Start up an EC2 instance and install mysql server on it.<\/li>\n<li>Configure the EC2 instance to be a replication master.<\/li>\n<\/ol>\n<p>To do this login into the EC2 machine and edit the my.cnf or my.ini file.<\/p>\n<p>Under the mysqld section enter the following two lines<\/p>\n<p><code>[mysqld]<br \/>\nlog-bin=mysql-bin<br \/>\nserver-id=1<\/code><br \/>\nRestart the mysql server<br \/>\n4.Create a user for replication<br \/>\nWe have to create a user account on the master that the slave can use for replication.<br \/>\nLog into mysql and run the following commands<\/p>\n<p><code>CREATE USER 'rep1'@'%' IDENTIFIED BY \u2018password';<br \/>\nGRANT REPLICATION SLAVE ON *.* TO 'rep1'@'%';<\/code><\/p>\n<p>5.Sync-up slave data with that of master and make sure the master is not undergoing any further updates.To achieve this first login to mysql and block all write statements with the below command.<\/p>\n<p><code>FLUSH TABLES WITH READ LOCK;<\/code><\/p>\n<p>Now take a mysqldump of the database.<\/p>\n<p><code>mysqldump \u2013u username \u2013ppassword dbname &gt; dump.sql<\/code><\/p>\n<p>Transfer the contents to the RDS database.<\/p>\n<p><code>mysql -u rdsuser -ppassword --host=RDS-endpoint --database=dbname &lt; dump.sql<\/code><\/p>\n<p>6.Next we need the masters binary log co-ordinates .During replication slave start processing events in the binary log from this point.<\/p>\n<p><code>SHOW MASTER STATUS;<br \/>\n+------------------+----------+--------------+------------------+<br \/>\n| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br \/>\n+------------------+----------+--------------+------------------+<br \/>\n| mysql-bin.000001 | 107 | | |<br \/>\n+------------------+----------+--------------+------------------+<\/code><\/p>\n<p>Now, login into the RDS instance to configure the slave.<\/p>\n<p>7.Configure RDS to use the EC2 instance as its replication master<br \/>\nLogin to RDS database and run the following command with the private ip of your ec2 instance, your replication username, password,your binary log name and co-ordinates.<\/p>\n<p><code>call mysql.rds_set_external_master('',3306,'rep1','password','mysql-bin.000001',107,0);<\/code><\/p>\n<p>8.Start replication with the command.<\/p>\n<p><code>call mysql.rds_start_replication;<\/code><br \/>\nConfirm replication is happening by running the command<\/p>\n<p><code>SHOW SLAVE STATUS\\G<\/code><\/p>\n<p>Look for<\/p>\n<p><code>Slave_IO_Running: Yes<br \/>\nSlave_SQL_Running: Yes<\/code><\/p>\n<p>9.Stop replication with the command.<\/p>\n<p><code>call mysql.rds_stop_replication;<\/code><\/p>\n<p>10.Once stopped you can configure a new replication master as follows.<br \/>\nFirst reset the external mysql master using the command.<\/p>\n<p><code>call mysql.rds_reset_external_master;<\/code><\/p>\n<p>Then set a new master using the mysql.rds_set_external_master command.<\/p>\n","protected":false},"author":219,"featured_media":0,"parent":0,"comment_status":"open","ping_status":"open","template":"","blog_category":[3606,3607],"user_email":"prarthitm@cloudthat.com","published_by":"324","primary-authors":"","secondary-authors":"","acf":[],"_links":{"self":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/1938"}],"collection":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/users\/219"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/comments?post=1938"}],"version-history":[{"count":1,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/1938\/revisions"}],"predecessor-version":[{"id":42737,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog\/1938\/revisions\/42737"}],"wp:attachment":[{"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/media?parent=1938"}],"wp:term":[{"taxonomy":"blog_category","embeddable":true,"href":"https:\/\/www.cloudthat.com\/resources\/wp-json\/wp\/v2\/blog_category?post=1938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}