Migrate MySQL to Azure Database for MySQL
1. Pre‑migration Checklist
- Verify MySQL version compatibility (Azure supports 5.6, 5.7, 8.0).
- Audit schema for unsupported features (e.g., spatial indexes).
- Estimate data size and plan Azure region & pricing tier.
- Ensure network connectivity (allow Azure IP ranges).
- Take a full logical backup of the source database.
2. Using Azure Database Migration Service (DMS)
DMS provides a guided, automated migration path. Follow these steps:
az dms create \
--resource-group MyResourceGroup \
--name mydms \
--location eastus \
--sku-name Standard_2vCores
az dms project create \
--resource-group MyResourceGroup \
--service-name mydms \
--name mysql-migration \
--source-platform MySQL \
--target-platform AzureDbForMySQL
az dms task create \
--resource-group MyResourceGroup \
--service-name mydms \
--project-name mysql-migration \
--name migrate-task \
--source-connection-json '{\"server\":\"source.mysql.local\",\"user\":\"admin\",\"password\":\"P@ssw0rd\",\"port\":3306}' \
--target-connection-json '{\"server\":\"myazuredb.mysql.database.azure.com\",\"user\":\"admin@myazuredb\",\"password\":\"P@ssw0rd\",\"port\":3306}' \
--database-options-json '{\"targetDatabaseName\":\"mydb\"}' \
--task-type OnlineMigration
Monitor the task via the Azure portal or with az dms task show.
3. Manual Migration with mysqldump
If you prefer a manual approach, export and import using mysqldump:
mysqldump -h source.mysql.local -u root -p --single-transaction --routines --triggers mydb > mydb.sql
mysql -h myazuredb.mysql.database.azure.com -u admin@myazuredb -p mydb < mydb.sql
4. Migration using MySQL Workbench
- Open MySQL Workbench → Database → Migration Wizard.
- Configure source and target connections.
- Select schemas to migrate.
- Review generated scripts and execute.
Workbench provides a visual preview of schema differences.
5. Post‑migration Validation
- Run
SELECT COUNT(*) FROM <table>;on source and target to verify row counts. - Check character set and collation using
SHOW VARIABLES LIKE 'character_set%'; - Test application connectivity and monitor latency.
- Configure firewall rules and enable TLS enforcement.
6. Clean‑up
After successful migration, you may decommission the on‑premises MySQL server or keep it as a read‑only replica.