Migrating MySQL to Cloud SQL with Minimal Downtime

ADP By islever Editorial Last updated

Short answer

C Use Database Migration Service to replicate the MySQL database to a Cloud SQL for MySQL instance.

Question

You are migrating data from a legacy on-premises MySQL database to Google Cloud. The database contains various tables with different data types and sizes, including large tables with millions of rows and transactional data. You need to migrate this data while maintaining data integrity, and minimizing downtime and cost. What should you do?
  1. Set up a Cloud Composer environment to orchestrate a custom data pipeline. Use a Python script to extract data from the MySQL database and load it to MySQL on Compute Engine.
  2. Export the MySQL database to CSV files, transfer the files to Cloud Storage by using Storage Transfer Service, and load the files into a Cloud SQL for MySQL instance.
  3. Use Database Migration Service to replicate the MySQL database to a Cloud SQL for MySQL instance. Correct Answer
  4. Use Cloud Data Fusion to migrate the MySQL database to MySQL on Compute Engine.

Key Takeaways

Use Database Migration Service for zero-downtime MySQL migration to Cloud SQL. This option wins because it uses continuous change data capture to maintain integrity and minimize downtime, unlike file-based or orchestration approaches.

Expert Analysis

Database Migration Service (DMS) migrates databases with minimal downtime using continuous change data capture.

The scenario presents a classic database migration challenge: moving from an on-premises MySQL source to Google Cloud while strictly balancing three competing constraints—data integrity, minimizing downtime, and cost efficiency. The correct strategy hinges on selecting a managed service designed specifically for stateful database replication rather than generic data transfer or orchestration tools. Option C, utilizing Database Migration Service (DMS) to replicate the MySQL database to a Cloud SQL for MySQL instance, is the only approach that satisfies all three constraints simultaneously through its architectural design.

Database Migration Service employs continuous change data capture (CDC) technology. This mechanism works by reading the binary logs of the source MySQL database in real-time and applying those changes to the target Cloud SQL instance concurrently. This architecture allows for a "zero-downtime" cutover strategy. The bulk load occurs first, followed by ongoing replication until the final switchover moment. Because the replication is automated and managed by DMS, it inherently preserves data integrity by ensuring that the target remains synchronized with the source up to the exact millisecond of cutover. Furthermore, since DMS is a fully managed Google Cloud service, it eliminates the operational overhead and potential licensing costs associated with self-managed infrastructure, thereby addressing the cost constraint more effectively than manual scripting approaches.

Option A suggests using Cloud Composer to orchestrate a custom Python script to move data between MySQL instances (on-premises to Compute Engine). This approach fails primarily on the "minimizing downtime" constraint. Custom scripts typically perform batch extracts and loads, which require the application to be taken offline during the transfer window to prevent data loss or inconsistency. Additionally, managing a MySQL instance on Compute Engine requires significant operational effort for patching, backups, and high availability configuration, which increases total cost of ownership compared to a managed service like Cloud SQL. It also reinvents the wheel by ignoring native CDC capabilities.

Option B proposes exporting to CSV files, transferring them via Storage Transfer Service, and loading them into Cloud SQL. While this minimizes some infrastructure costs, it is fundamentally incompatible with maintaining data integrity and minimizing downtime for transactional data. CSV exports do not preserve database-specific metadata such as stored procedures, triggers, foreign key constraints, or auto-increment sequences. More critically, the process is sequential and static; there is no mechanism to capture changes that occur on the source database while the export and load are happening. This results in a significant data gap, violating the integrity requirement unless the source is locked read-only for the duration of the transfer, which directly contradicts the goal of minimizing downtime.

Option D recommends using Cloud Data Fusion to migrate to MySQL on Compute Engine. Like Option A, this targets a self-managed MySQL instance, incurring higher operational costs and complexity. While Cloud Data Fusion is a powerful ETL tool, it is generally optimized for structured data pipelines and may not handle complex schema migrations or full database replication features (like automatic failover setup or seamless CDC integration with the target engine) as seamlessly as a purpose-built database migration service. Using an ETL tool for a full database lift-and-shift introduces unnecessary complexity and risk of data type mapping errors compared to DMS.

The decisive factor here is the specific capability of Continuous Change Data Capture. Only DMS provides the automated, low-latency replication required to keep the cloud replica fresh without stopping the source. Generic file transfer services (Storage Transfer Service) and orchestration frameworks (Cloud Composer, Data Fusion) are infrastructure or pipeline tools, not database migration engines. They lack the deep integration with MySQL's binary log protocol needed for safe, consistent, and rapid migration.

Official Reference

https://cloud.google.com/database-migration-service/docs/overview

This link opens the official vendor documentation in a new tab.

Practice All ADP Questions

Access 65 questions with complete answers and detailed explanations.

View Full ADP Practice Test →

← Back to ADP Study Guide