Tutorial: Migrate RDS MySQL to Azure Database for MySQL online using DMS
You can use Azure Database Migration Service to migrate databases from an RDS MySQL instance to Azure Database for MySQL while the source database remains online during migration. In other words, migration can be achieved with minimal downtime to the application. In this tutorial, you migrate the Employees sample database from an instance of RDS MySQL to Azure Database for MySQL by using the online migration activity in Azure Database Migration Service.
In this tutorial, you learn how to:
- Migrate the sample schema by using the mysqldump and mysql utilities.
- Create an instance of Azure Database Migration Service.
- Create a migration project by using Azure Database Migration Service.
- Run the migration.
- Monitor the migration.
Using Azure Database Migration Service to perform an online migration requires creating an instance based on the Premium pricing tier. For more information, see the Azure Database Migration Service pricing page.
For an optimal migration experience, Microsoft recommends creating an instance of the Azure Database Migration Service in the same Azure region as the target database. Moving data across regions or geographies can slow down the migration process and introduce errors.
When you migrate databases to Azure by using Azure Database Migration Service, you can do an offline or an online migration. With an offline migration, application downtime starts when the migration starts. With an online migration, downtime is limited to the time to cut over at the end of migration. We suggest that you test an offline migration to determine whether the downtime is acceptable; if not, do an online migration.
This article describes how to perform an online migration from an instance of RDS MySQL to Azure Database for MySQL.
To complete this tutorial, you need to:
Ensure that the source MySQL server is running a supported MySQL community edition. To determine the version of your MySQL instance, in the mysql utility or MySQL Workbench, run the command:
For more information, see the article Supported Azure Database for MySQL versions.
Download and install the MySQL Employees sample database.
Create an instance of Azure Database for MySQL.
Create a Microsoft Azure Virtual Network for Azure Database Migration Service by using the Azure Resource Manager deployment model, which provides site-to-site connectivity to your on-premises source servers by using either ExpressRoute or VPN. For more information about creating a virtual network, see the Virtual Network Documentation, and especially the quickstart articles with step-by-step details.
Ensure that your virtual network Network Security Group rules don't block the following inbound communication ports to Azure Database Migration Service: 443, 53, 9354, 445, and 12000. For more detail on virtual network NSG traffic filtering, see the article Filter network traffic with network security groups.
Configure your Windows Firewall (or your Linux firewall) to allow for database engine access. For MySQL server, allow port 3306 for connectivity.
Azure Database for MySQL only supports InnoDB tables. To convert MyISAM tables to InnoDB, please see the article Converting Tables from MyISAM to InnoDB .
Set up AWS RDS MySQL for replication
- To create a new parameter group, follow the instructions provided by AWS in the article MySQL Database Log Files, in the Binary Logging Format section.
- Create a new parameter group with the following configuration:
- binlog_format = row
- binlog_checksum = NONE
- Save the new parameter group.
- Associate the new parameter group with the RDS MySQL instance. A reboot might be required.
Migrate the schema
Extract the schema from the source database and apply to the target database to complete migration of all database objects such as table schemas, indexes, and stored procedures.
The easiest way to migrate only the schema is to use mysqldump with the --no-data parameter. The command to migrate the schema is:
mysqldump -h [servername] -u [username] -p[password] --databases [db name] --no-data > [schema file path]
For example, to dump a schema file for the Employees database, use the following command:
mysqldump -h 10.10.123.123 -u root -p --databases employees --no-data > d:\employees.sql
Import the schema to target service, which is Azure Database for MySQL. To restore the schema dump file, run the following command:
mysql.exe -h [servername] -u [username] -p[password] [database]< [schema file path]
For example, to import the schema for the Employees database:
mysql.exe -h shausample.mysql.database.azure.com -u dms@shausample -p employees < d:\employees.sql
If you have foreign keys in your schema, the initial load and continuous sync of the migration will fail. To extract the drop foreign key script and add foreign key script at the destination (Azure Database for MySQL), run the following script in MySQL Workbench:
SET group_concat_max_len = 8192; SELECT SchemaName, GROUP_CONCAT(DropQuery SEPARATOR ';\n') as DropQuery, GROUP_CONCAT(AddQuery SEPARATOR ';\n') as AddQuery FROM (SELECT KCU.REFERENCED_TABLE_SCHEMA as SchemaName, KCU.TABLE_NAME, KCU.COLUMN_NAME, CONCAT('ALTER TABLE ', KCU.TABLE_NAME, ' DROP FOREIGN KEY ', KCU.CONSTRAINT_NAME) AS DropQuery, CONCAT('ALTER TABLE ', KCU.TABLE_NAME, ' ADD CONSTRAINT ', KCU.CONSTRAINT_NAME, ' FOREIGN KEY (`', KCU.COLUMN_NAME, '`) REFERENCES `', KCU.REFERENCED_TABLE_NAME, '` (`', KCU.REFERENCED_COLUMN_NAME, '`) ON UPDATE ',RC.UPDATE_RULE, ' ON DELETE ',RC.DELETE_RULE) AS AddQuery FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE KCU, information_schema.REFERENTIAL_CONSTRAINTS RC WHERE KCU.CONSTRAINT_NAME = RC.CONSTRAINT_NAME AND KCU.REFERENCED_TABLE_SCHEMA = RC.UNIQUE_CONSTRAINT_SCHEMA AND KCU.REFERENCED_TABLE_SCHEMA = 'SchemaName') Queries GROUP BY SchemaName;
Run the drop foreign key (which is the second column) in the query result to drop the foreign key.
If you have triggers (insert or update trigger) in the data, it will enforce data integrity in the target before replicating data from the source. The recommendation is to disable triggers in all the tables at the target during migration, and then enable the triggers after migration is complete.
To disable triggers in target database:
select concat ('alter table ', event_object_table, ' disable trigger ', trigger_name) from information_schema.triggers;
If there are instances of the ENUM data type in any tables, we recommend temporarily updating to the ‘character varying’ datatype in the target table. WHen data replication is complete, then revert the data type to ENUM.
Register the Microsoft.DataMigration resource provider
Sign in to the Azure portal, select All services, and then select Subscriptions.
Select the subscription in which you want to create the instance of Azure Database Migration Service, and then select Resource providers.
Search for migration, and then to the right of Microsoft.DataMigration, select Register.
Create an instance of Azure Database Migration Service
In the Azure portal, select + Create a resource, search for Azure Database Migration Service, and then select Azure Database Migration Service from the drop-down list.
On the Azure Database Migration Service screen, select Create.
On the Create Migration Service screen, specify a name for the service, the subscription, and a new or existing resource group.
Select the location in which you want to create the instance of Azure Database Migration Service.
Select an existing virtual network or create a new one.
The virtual network provides Azure Database Migration Service with access to the source MySQL instance and the target Azure Database for MySQL instance.
For more information about how to create a virtual network in the Azure portal, see the article Create a virtual network using the Azure portal.
Select a pricing tier; for this online migration, be sure to select the Premium: 4vCores pricing tier.
Select Create to create the service.
Create a migration project
After the service is created, locate it within the Azure portal, open it, and then create a new migration project.
In the Azure portal, select All services, search for Azure Database Migration Service, and then select Azure Database Migration Services.
On the Azure Database Migration Services screen, search for the name of the Azure Database Migration Service instance that you created, and then select the instance.
Select + New Migration Project.
On the New migration project screen, specify a name for the project, in the Source server type text box, select MySQL, and then in the Target server type text box, select AzureDbForMySQL.
In the Choose type of activity section, select Online data migration.
Be sure to select Online data migration; offline migrations are not supported for this scenario.
Alternately, you can choose Create project only to create the migration project now and execute the migration later.
Select Create and run activity to create the project and run the migration activity.
Please make a note of the pre-requisites needed to set up online migration in the project creation blade.
Specify source details
On the Migration source detail screen, specify the connection details for the source MySQL instance.
Specify target details
Select Save, and then on the Target details screen, specify the connection details for the target Azure Database for MySQL server, which is pre-provisioned and has the Employees schema deployed using MySQLDump.
Select Save, and then on the Map to target databases screen, map the source and the target database for migration.
If the target database contains the same database name as the source database, Azure Database Migration Service selects the target database by default.
Select Save, on the Migration summary screen, in the Activity name text box, specify a name for the migration activity, and then review the summary to ensure that the source and target details match what you previously specified.
Run the migration
Select Run migration.
The migration activity window appears, and the Status of the activity is Initializing.
Monitor the migration
On the migration activity screen, select Refresh to update the display until the Status of the migration shows as Running.
Under DATABASE NAME, select a specific database to get to the migration status for Full data load and Incremental data sync operations.
Full data load shows the initial load migration status, while Incremental data sync shows change data capture (CDC) status.
Perform migration cutover
After the initial Full load is completed, the databases are marked Ready to Cutover.
When you're ready to complete the database migration, select Start Cutover.
Make sure to stop all the incoming transactions to the source database; wait until the Pending changes counter shows 0.
Select Confirm, and the select Apply.
When the database migration status shows Completed, connect your applications to the new target Azure Database for MySQL database.
Your online migration of an on-premises instance of MySQL to Azure Database for MySQL is now complete.