Google Cloud: Migrating On-premises MySQL Using a Continuous Database Migration Service Job

Share At:

Prisma Migrate is Production Ready - Hassle-Free Database Migrations

Activate Google Cloud Shell

Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Google Cloud Shell provides command-line access to your GCP resources.

  1. In GCP console, on the top right toolbar, click the Open Cloud Shell butCloud Shell icon
  2. Click Continue
cloudshell_continue.png

It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID.

gcloud is the command-line tool for Google Cloud Platform. It comes pre-installed on Cloud Shell and supports tab-completion.

You can list the active account name with this command:

gcloud auth list

You can list the project ID with this command:

gcloud config list project

Verify that the Database Migration API is enabled

  1. In the Google Cloud Console, enter Database Migration API in the top search bar. Click on the result for Database Migration API.

This page will either show status information or give you the option to enable the API.

  1. If necessary, enable the API.

Verify that the Service Networking API is enabled

  1. In the Google Cloud Console, enter Service Networking API in the top search bar. Click on the result for Service Networking API.

This page will either show status information or give you the option to enable the API.

  1. If necessary, enable the API.

Task 1. Get the connectivity information for the MySQL source instance

In this task, you identify the internal IP address of the source database instance that you will migrate to Cloud SQL.

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Compute Engine > VM instances.
  2. Locate the line with the instance called dms-mysql-training-vm-v2.
  3. Copy the value for Internal IP (e.g., 10.128.0.2).

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

A connection profile stores information about the source database instance (e.g., on-premises MySQL) and is used by Database Migration Service to migrate data from the source to your destination Cloud SQL database instance. After you create a connection profile, it can be reused across migration jobs.

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Database Migration > Connection profiles.
  1. Click Create Profile.
  2. For Source database engine, select MySQL.
  3. Enter the required information for a connection profile:
PropertyValue
Connection profile namemysql-vm
Connection profile IDkeep the auto-generated value
Hostname or IP addressenter the internal IP for the MySQL source instance that you copied in the previous task (e.g., 10.128.0.2)
Port3306
Usernameadmin
Passwordchangeme
  1. For the Encryption Type, select None.
  2. Click Create.

7. A new connection profile named mysql-vm will appear in the Connections profile list.

Task 3. Create and start a continuous migration job

When you create a new migration job, you first define the source database instance using a previously created connection profile. Then you create a new destination database instance and configure connectivity between the source and destination instances.

In this task, you use the migration job interface to create a new Cloud SQL for MySQL database instance and set it as the destination for the continuous migration job from the MySQL source instance.

Create a new continuous migration job

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Database Migration > Migration jobs.
  2. Click Create Migration Job.
  1. For Create a migration job, on the Get Started tab, use the following values:
PropertyValue
Migration job namevm-to-cloudsql
Migration job IDkeep the auto-generated value
Source database engineMySQL
Migration job typeContinuous

Leave all other settings as default.

  1. Click Save & Continue.

Define the source instance

  1. For source connection profile, select mysql-vm.
  2. Leave the defaults for the other settings.
  3. Click Save & Continue.

Create the destination instance

  1. Enter the required information to create the destination instance on Cloud SQL:
PropertyValue
Destination Instance IDmysql-cloudsql
Root passwordsupersecret!
Database versionCloud SQL for MySQL 5.7
ZoneAny
  1. For Instance connectivity, select Private IP and Public IP.
  2. Select Use an automatically allocated IP range.
  3. Click Allocate & Connect.

This step may take a few minutes. If asked to retry the request, click the Retry button to refresh the Service Networking API.

When this step is complete, an updated message notifies you that the instance will use the existing managed service connection.

The updated message says that the instance will use the existing managed service connection.
  1. Enter the additional information needed to create the destination instance on Cloud SQL:
PropertyValue
Machine typedb-n1-standard-1
Storage typeSSD
Storage capacity10
  1. Click Create & Continue.

If prompted to confirm, click Create Destination & Continue.

Define the connectivity method

A message will state that your destination database instance is being created. Continue to step 1 while you wait.

The message states that the button for configure & continue is enabled when the destination Cloud SQL instance has been created.
  1. For Connectivity method, select VPC peering.
  2. For VPC, select default.

VPC peering is configured by Database Migration Service using the information provided for the VPC network (the default network in this example).

When you see an updated message that the destination instance was created, proceed to the next step.

The updated message informs you that the destination Cloud SQL instance has been created.
  1. Click Configure & Continue.

Test and start the continuous migration job

  1. Review the details of the migration job.
  2. Click Test Job.
  1. After a successful test, click Create & Start Job.
Be sure to click on the button for create & start job to ensure that the job is successfully started.

4. If prompted to confirm, click Create & Start.

Task 4. Review the status of the continuous migration job

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Database Migration > Migration jobs.
  2. Click the migration job vm-to-cloudsql to see the details page.
  3. Review the migration job status.
    • If you have not started the job, the status will show as Not started. You can choose to start or delete the job.
    • After the job has started, the status will show as Starting and then transition to Running Full Dump to indicate that the initial database dump is in progress.
    • After the initial database dump has been completed, the status will transition to Running CDC in progress to indicate that continuous migration is active.

4. When the job status changes to Running CDC in progress, proceed to the next task.

Continuous migration jobs remain in a running status to ensure that the destination database continues to receive data updates from the source.

A completed status is achieved after the destination database is promoted to be a standalone database for reading and writing data (see task 7).

Task 5. Confirm the data in Cloud SQL for MySQL

Check the MySQL databases in Cloud SQL

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Databases > SQL.
  2. Click on the instance ID called mysql-cloudsql (MySQL read replica).
  1. In the Replica Instance menu, click Databases.

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

Connect to the MySQL instance

  1. In the Replica Instance menu, click Overview.
  2. Click Connect using Cloud Shell.

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:
supersecret!

You have now activated the MySQL interactive console for the destination instance.

Review the data in the Cloud SQL for MySQL instance

  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;

There are 5,030 records in the customers table that was migrated from the MySQL source instance.

  1. Sort the records in the customers table by last name and review the first ten records:
select * from customers
order by lastName
limit 10;

Note that the last name of the first record in the customers table is Accumsan.

In the next task, you will add new records to the customers table in the source database instance. The continuous migration job will migrate the new records from the source instance to the destination instance.

  1. Exit the MySQL interactive console:
exit

Task 6. Test the continuous migration of data from the source to the destination instance

Add new data to the source instance

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Compute Engine > VM instances.
  2. Locate the line with the instance called dms-mysql-training-vm-v2.
  3. For Connect, click SSH to open a terminal window.
  4. To connect to the MySQL interactive console within the terminal window, run the following command:
mysql -u admin -p
  1. When prompted for a password, enter:
changeme
  1. To select the database in the MySQL interactive console, run the following command:
use customers_data;
  1. Add two new data records to the customers table with the following command:
INSERT INTO customers (customerKey, addressKey, title, firstName, lastName, birthdate, gender, maritalStatus, email, creationDate)
VALUES ('9365552000000-999', '9999999', 'Ms', 'Magna', 'Ablorem', '1953-07-28 00:00:00', 'FEMALE', 'MARRIED', 'magna.lorem@gmail.com', CURRENT_TIMESTAMP),
('9965552000000-9999', '99999999', 'Mr', 'Arcu', 'Abrisus', '1959-07-28 00:00:00', 'MALE', 'MARRIED', 'arcu.risus@gmail.com', CURRENT_TIMESTAMP);
  1. Query the new number of records in the customers table:
select count(*) from customers;

There are now 5,032 records in the customers table in the MySQL source instance.

  1. Sort the records in the customers table by last name and review the first ten records:
select * from customers
order by lastName
limit 10;

Note that the last name of the first record in the customers table has changed to Ablorem.

  1. Exit the MySQL interactive console:
exit
  1. Exit the terminal session:
exit

Connect to the Cloud SQL for MySQL instance

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Databases > SQL.
  2. Click on the instance ID called mysql-cloudsql (MySQL read replica).
  3. In the Replica Instance menu, click Overview.
  4. Click Connect using Cloud Shell.

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:
supersecret!

You have now activated the MySQL interactive console for the destination instance.

Check that the data updates have been applied to the Cloud SQL for MySQL instance

  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;

Notice that the two records added to the MySQL source instance have been migrated. There are now 5,032 records in the customers table in the Cloud SQL destination instance.

  1. Sort the records in the customers table by last name and review the first ten records:
select * from customers
order by lastName
limit 10;

Notice that the last name of the first record in the customers table is now the same across the Cloud SQL destination instance and the MySQL source instance.

  1. Exit the MySQL interactive console:
exit

Task 7. Promote Cloud SQL to be a standalone instance for reading and writing data

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Database Migration > Migration jobs.
  1. Click the migration job name vm-to-cloudsql to see the details page.
  2. Click Promote.

If prompted to confirm, click Promote.

4. When the promotion is complete, the status of the job will update to completed.

  1. In the Google Cloud Console, on the Navigation menu (nav-menu.png), click Databases > SQL.

Note that mysql-cloudsql is now a standalone instance for reading and writing data.

We have completed the database migration.

Happy Learning !!!


Share At:
0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
gate token yorum
15 days ago

I am a student of BAK College. The recent paper competition gave me a lot of headaches, and I checked a lot of information. Finally, after reading your article, it suddenly dawned on me that I can still have such an idea. grateful. But I still have some questions, hope you can help me.

Back To Top

Contact Us