Migrating to Cloud SQL from Amazon RDS for MySQL Using Database Migration Service

Biswanath Giri
4 min readOct 17, 2022

--

Architecture Diagram

Objectives

How to configure a one-time Database Migration Service job to migrate databases from a cloud-based MySQL instance to Cloud SQL for MySQL.

  • Create a profile for a source connected to a cloud-based MySQL instance (Amazon RDS for MySQL).
  • Configure connectivity between source and destination instances using an IP allowlist.
  • Create and run a one-time migration job using Database Migration Service.
  • Verify that the migration job has completed successfully.

Prerequisites

Database Migration API is enabled

  1. To install dig in Cloud Shell, run the following command:
sudo apt-get update && sudo apt-get install dnsutils -y

dig HOSTNAME

copy ip name ex: 169.254.169.254

Task 1. Install and configure the AWS CLI tool in GCP Cloud Shell

curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
  1. To configure the AWS CLI tool in Cloud Shell, run the following command:
aws configure

AWS Access Key ID [None] enter the provided value for AWS Access Key

AWS Secret Access Key [None] enter the provided value for AWS Secret Key

Default region name [None] put region name

Default output format [None] to accept the default

Task 2. Create a new connection profile for the Amazon RDS instance for MySQL

  1. In the Google Cloud Console, on the Navigation menu

click Database Migration > Connection profiles.

  1. Click Create Profile.
  2. For Source database engine, select Amazon RDS for MySQL.
  3. Enter the required information for a connection profile:

Connection profile name — — -mysql-rds

Connection profile ID — — -put value

Hostname or IP address — -enter the IP address you identified for the Amazon RDS instance in the Setup tasks (such as 54.84.181.60)

Port — -put 3306

Username — — — — — — — — -ex:-admin

Password — — — — — — — ex:- changeme

  1. For Region, select us-central1 (Iowa).
  2. For the Encryption Type, select None.

Click Create.

Task 3. Create a one-time migration job

  1. In the Google Cloud Console, on the Navigation menu (
  2. ), click Database Migration > Migration jobs.
  3. Click Create Migration Job.
  4. For Create a migration job, on the Get Started tab, use the following values:
  5. Migration job name rds-to-cloudsql
  6. Migration job ID keep the auto-generated value
  7. Source database engineAmazon RDS for MySQL
  8. Destination regionus-central1 (Iowa)
  9. Migration job typeOne-time
  10. Leave all other settings as default.
  11. Click Save & Continue.

Define the source instance

  1. For source connection profile, select mysql-rds.
  2. Click Save & Continue.

Create the destination instance

Destination Instance ID mysql-cloudsql

User Root

password — — — — — — — — — — supersecret

Database version Cloud SQL for MySQL 5.7

Zone Any

Connections Public IP

Machine type — — -Standard (1 vCPU, 3.75 GB)

Storage type SSD

Storage capacity 10

  1. Click Create & Continue.
  2. When prompted to confirm, click Create Destination & Continue.

Define the connectivity method

  1. For Connectivity method, select IP allowlist.

When the destination database (Cloud SQL for MySQL) is created, the IP address will be available.

  1. Copy the Destination outgoing IP address (such as 35.239.140.158) to configure the IP allowlist on the Amazon RDS instance.
  2. Click Save & Continue.

Task 4. Configure the IP allowlist on source instance

  • To modify the IP allowlist on the Amazon RDS instance, run the following command in Cloud Shell:
  • Replace <sg_id> with the provided value for AWS RDS Database Security Group (such as sg-06700713f70076ad8) on this page, and replace <a.b.c.d> with the Destination outgoing IP address of your Cloud SQL instance (such as 35.239.140.158).
aws ec2 authorize-security-group-ingress \
--group-id <sg-id> \
--protocol tcp \
--port 3306 \
--cidr <a.b.c.d>/32

Task 5. Test and run a one-time migration job

  1. Return to the migration job window and review the summary.
  2. Click Test Job.
  3. After a successful test, click Create & Start Job.

Task 6. Review status of the one-time migration job in DMS

  1. In the Google Cloud Console, on the Navigation menu (
  2. click Database Migration > Migration jobs.
  3. Click the migration job rds-to-cloudsql to see the details page.
  4. Review the migration job status.

Task 7. Confirm the data in Cloud SQL for MySQL

Check MySQL databases in Cloud SQL

  1. In the Google Cloud Console, on the Navigation menu (
  2. click Databases > SQL.
  3. Click on the instance ID called mysql-cloudsql.
  4. In the Primary Instance menu, click Databases.

Notice that the databases called customers_data and sales_data have been migrated to Cloud SQL.

Connect to MySQL database

  1. In the Primary Instance menu, click Overview.
  2. In Connect to this instance panel, click on Open cloud shell button.

The command to connect to MySQL will pre-populate in Cloud Shell:

gcloud sql connect mysql-cloudsql --user=root --quiet
  1. Run the pre-populated command.

If prompted, click Authorize for the API.

  1. When prompted for a password, which you previously set, enter:

password

Review data in Cloud SQL for MySQL database

  1. To select the database in the MySQL interactive console, run the following command:
use customers_data;
  1. Query the number of records in the customers table:
select count(*) from customers;

--

--

Biswanath Giri
Biswanath Giri

Written by Biswanath Giri

Cloud & AI Architect | Empowering People in Cloud Computing, Google Cloud AI/ML, and Google Workspace | Enabling Businesses on Their Cloud Journey

No responses yet