This page describes how to migrate your databases to a pre-existing Cloud SQL
instance created directly in Cloud SQL.

This path is useful for scenarios where your destination instance is managed by
a different team, or you if you need to create the instance outside Database Migration Service
(for example if you use Terraform). If your migration has different
requirements, consider following a different migration flow. For more information,
see [Get started with MySQL migrations](https://docs.cloud.google.com/database-migration/docs/mysql/get-started-with-mysql-migrations.md.txt).

At a high level, the migration follows these steps:

1. Configure the source database to allow Database Migration Service to move your data to the new databases.
2. Set up the network connectivity to your source MySQL instance.
3. Create the connection profile and the migration job.
4. Start and monitor the migration job.
5. Promote the migration job and move your application to use the new databases.

## Costs

In this document, you use the following billable components of
Google Cloud:

- Cloud SQL (See [Cloud SQL pricing](https://docs.cloud.google.com/sql/pricing).)
- If used for storing Customer-managed Encryption Keys (CMEK): Cloud Storage (See [Cloud Storage pricing](https://docs.cloud.google.com/storage/pricing).)

To generate a cost estimate based on your projected usage, use the
[pricing calculator](https://docs.cloud.google.com/products/calculator).

## Before you begin

1. Verify if this migration path can fully support your scenario. See the following pages:
   - [Supported sources and destinations](https://docs.cloud.google.com/database-migration/docs/mysql/scenario-overview.md.txt#supported-src-and-dest) on the *Scenario overview* page lists all supported source and destination versions.
   - [Known limitations](https://docs.cloud.google.com/database-migration/docs/mysql/known-limitations.md.txt) describes supported data types, database sizes, and other limitations.
2. *For one-time migrations*: Consider the schedule for your migration. One-time migrations perform only a full dump and load operation without subsequent change data capture. We recommend that you disable writes on your source database for the migration process to avoid losing data.
3. Consider in which region you want to create the destination database. Database Migration Service is a fully-regional product, meaning all entities related to your migration (source and destination connection profiles, migration jobs, destination databases, conversion workspaces) must be saved in a single region.
4. In the Google Cloud console, on the project selector page, select or [create a Google Cloud project](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt).

   [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)
5. Enable the Database Migration Service and Cloud SQL Admin APIs. [Enable the APIs](https://console.cloud.google.com/flows/enableapi?apiid=datamigration.googleapis.com,sqladmin.googleapis.com)

### Required roles

To get the permissions that you need to perform homogeneous MySQL
migrations with Database Migration Service, ask your administrator to grant you the
required IAM roles on your project:

- [Database Migration Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/datamigration.md.txt#datamigration.admin) (`roles/datamigration.admin`)
- If you need to create the destination instance outside Database Migration Service, you also need [Cloud SQL Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/cloudsql.md.txt#cloudsql.admin) (`roles/cloudsql.admin`)

For more information about granting roles, see
[Manage access](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access.md.txt) in the Identity and Access Management documentation.

These predefined roles contain the permissions required to perform
homogeneous MySQL migrations with Database Migration Service. To see the exact
permissions that are required, expand the
**Required permissions** section:

#### Required permissions

The following permissions are required to perform homogeneous MySQL
migrations with Database Migration Service:

- `datamigration.*`
- `cloudsql.instances.create`
- `cloudsql.instances.get`
- `cloudsql.instances.list`
- `cloudsql.instances.update`
- `cloudsql.instances.delete`
- `cloudsql.operations.get`
- `cloudsql.users.list`
- `cloudsql.users.get`
- `cloudsql.users.create`
- `cloudsql.users.update`
- `cloudsql.users.delete`

You might also be able to get these permissions with
[custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or other
[predefined roles](https://docs.cloud.google.com/iam/docs/roles-permissions.md.txt).

## Prepare your source database

To prepare your source data for migration, follow these steps:

1. Consider if you want to provide your own dump files or have Database Migration Service perform the full dump automatically:
   - **Automatic dump (default)**: Database Migration Service connects to your source database and performs the initial schema and data dump automatically when the migration job starts. You don't need to prepare anything before you begin the migration.
   - **Manual dump** : You can generate your own dump files and upload them to a Cloud Storage bucket. This approach can be useful if you want to reduce the initial load on your primary instance and take the full dump from a replica, run the dump during a specific maintenance window, or pass custom export flags. See [Export a MySQL database with `mysqldump`](https://docs.cloud.google.com/database-migration/docs/mysql/mysql-dump.md.txt).
2. [Choose and configure your source network connectivity method](https://docs.cloud.google.com/database-migration/docs/mysql/networking-methods.md.txt).
3. Configure your source database instance.
   - For **continuous** migrations, see [Configure source database for continuous migrations](https://docs.cloud.google.com/database-migration/docs/mysql/configure-source-database-continuous.md.txt).
   - For **one-time** migrations, see [Configure source database for one-time migrations](https://docs.cloud.google.com/database-migration/docs/mysql/configure-source-database.md.txt).
4. [Create a source connection profile](https://docs.cloud.google.com/database-migration/docs/mysql/create-connection-profiles.md.txt).

## Create and configure your destination instance

In certain scenarios, you might want to pre-create your destination instance
directly in Cloud SQL to leverage all the available configuration options.

- If you want to create the destination directly in Cloud SQL, carefully
  consider the network type of your destination machine:

  - If you want to use Private Service Connect interfaces connectivity, create the destination instance as a PSC-enabled instance. See [Create a PSC-enabled instance](https://docs.cloud.google.com/sql/docs/mysql/configure-private-service-connect.md.txt#create-cloud-sql-instance-psc-enabled-2).
  - If you want to use Virtual Private Cloud peering connectivity, create the destination instance as a PSA instance. See [Create a database instance](https://docs.cloud.google.com/sql/docs/mysql/create-instance.md.txt).
  - If you want to use public IP allowlist connectivity, create the destination instance with a public IP enabled. See [Create a database instance](https://docs.cloud.google.com/sql/docs/mysql/create-instance.md.txt).
- If you already have an existing destination Cloud SQL instance, you can
  proceed to the next section.

## Create and run the migration job

To configure and run your migration, perform the following steps:

1. Optional: If you want to manage your own certificates for the migration job, [prepare the necessary encryption keys](https://docs.cloud.google.com/sql/docs/mysql/configure-cmek.md.txt).
2. [Create and run the migration job](https://docs.cloud.google.com/database-migration/docs/mysql/create-migration-job-existing-instance.md.txt).

   You can monitor the migration progress, as well as your destination instance
   health with Database Migration Service observability
   features. See
   [Migration job metrics](https://docs.cloud.google.com/database-migration/docs/mysql/migration-job-metrics.md.txt).

## Finalize the migration

When you decide to switch your application to the new Cloud SQL for MySQL
instance, finalize the migration by following these steps:

### Continuous migrations

1. *Optional*: [Set up cascading read replicas](https://docs.cloud.google.com/database-migration/docs/mysql/set-up-cascading-replica.md.txt). If you want to use cascading read replicas, you can configure them when the migration job enters the CDC phase.
2. Stop all write operations on your source database. You can switch them to read-only mode to retain operational functionality.
3. [Promote the migration job](https://docs.cloud.google.com/database-migration/docs/mysql/promote-migration.md.txt).
4. Optional: [Verify migration data](https://docs.cloud.google.com/database-migration/docs/mysql/verify-migration.md.txt) for completeness.

### One-time migrations

When Database Migration Service completes the full dump phase, the destination
instance is automatically promoted to a standalone instance. To finalize
the migration, follow these steps:

1. Optional: [Verify migration data](https://docs.cloud.google.com/database-migration/docs/mysql/verify-migration.md.txt) for completeness.
2. Switch your application to connect to the new Cloud SQL for MySQL instance.

## What's next

Learn more about Google Cloud features for Cloud SQL for MySQL. See
[Cloud SQL for MySQL features](https://docs.cloud.google.com/sql/docs/mysql/features.md.txt).