How to move MySql database from AWS RDS to Azure ?


There are several ways to backup mysql databases, as shown at Mysql Backup and Recovery. In this post I have shown AWS RDS mysql backup using mysqldump utility, and restore to Azure using mysql command. This may not be the ideal way when you need to move very large databases.

Note! Please do have a look at the more recent documentation in this context at https://docs.microsoft.com/en-us/azure/mysql/concepts-migrate-import-export

Overview
We need to first have machine where we can execute the mysqldump and mysql commands. If you already have such a machine you can directly start from step 2.

  1. Setting up migration script execution machine : I have used the Centos 6.7 VM image from Azure, to create the script execution VM. This VM is needed to execute the backup and restore commands. Once the the VM has been created ssh on the vm and execute the following command to install the mysql client utilities:
    sudo yum install mysql

     

  2. Backing up AWS RDS MySql database to file : you will need the FQDN, database name, username and password of your AWS RDS mysql instance to execute the following command, which will create backup file for your database. Please make sure that the RDS MySql instance is accessible from the script execution vm (setting in AWS):
    mysqldump -h rdsmysqlserverfqdn -P 3306 databasename > dbbackupfile.sql -u dbusername -p

    You will be prompted to enter your RDS MySql password after you execute this command. After execution is complete you will see the backup file dbbackupfile.sql in your directory

  3. Restoring database toAzure : Azure has both PaaS (ClearDB) and IaaS option for MySql.
    • Restore to ClearDB (PaaS) : This link shows how to create a ClearDB MySql instance. We need the ClearDB server name, database name, username and password to restore the database from backup. Once you have these details execute the following command :
      mysql -h cleardb_server_name -P 3306 -u cleardb_username -p cleardb_databasename < dbbackupfile.sql

      You will be prompted to enter your ClearDB password after you execute this command. After execution is complete you will see that the database has been restored

    • Restore to MySql deployed to VMs: One of the most popular MySQL Master-Slave setups can be achieved by deploying the mysql-replication ARM template (by clicking on deploy to azure button). The Readme.md file of this template has instructions to do various things including backing up the database to azure blob storage. Once this template has been deployed we need to restore the backup using the following script:
      mysql -h serverfqdn -P 3306 -u admin -p -D test < dbbackupfile.sql

      You will be prompted to enter your admin password after you execute this command. After execution is complete you will see that the test database has been restored



    Thanks for reading my blog. I hope you liked it. Please feel free to write your comments and views about the same over here or at @manisbindra

Comments (0)

Skip to main content