MySQL Database migration to Google Cloud SQL

Mayank Chourasia
2 min readSep 14, 2020

--

Hello Everyone, Hope you are well..!!

In this guide, we learn how to migrate the MySQL database to Google Cloud SQL, this means you will be able to host a MySQL database in Cloud SQL, and access it from ‘just about any application, running anywhere’’..

Google Cloud SQL is a fully-managed database service that makes it easy to set-up, maintain, manage, and administer your relational MySQL databases in the cloud.

The steps to migrate MySQL database to Google Cloud SQL are:

  1. Create a dump file from your MySQL server.
  2. Log IN to your GCP Console.
  3. Make a project.
  4. Create a Google Cloud Storage bucket.
  5. Copy the dump file in the GCP bucket.
  6. Create a Cloud SQL for SQL Server instance.
  7. Import the database into Cloud SQL for SQL Server from GCP bucket.

1.Create a dump file from your MySQL server: Login to the MySQL server, use mysqldump to export the MySQL database to a dump file with the following flags:

mysqldump — databases database_name-h localhost -u blogadmin -p — hex-blob — skip-triggers — single-transaction — default-character-set=utf8mb4 > database_name.sql

2. Open Cloud Shell and Create a Google Cloud Storage bucket: You can create a Google Cloud Storage bucket using the following command

gsutil mb gs://[bucket-name]

Note:bucket-name refers to a Unique Name we have to give.

3. Copy the dump file in the GCP bucket: You can copy the dump file into the Google Cloud Storage bucket using this command

gsutil cp ~/database_name.sql gs://[bucket-name]

4. Create a Cloud SQL for SQL Server instance: In the GCP console, navigate to SQL and click Create instance. Click on MySQL and give any name to the SQL instance, e.g. demo. Generate a root password and then click Create.

5.Import the database into Cloud SQL for SQL Server from GCP bucket

  1. From the GCP console go to Cloud SQL.
  2. Click on the SQL instance name then click on the Database tab.
  3. Create Database.
  4. Enter the database name then click on Create.
  5. Navigate to the overview tab and click on import.
  6. In source field, browse the sql dump file from cloud storage bucket which we have created already.
  7. Select format of file as SQL.
  8. In the destination field, select the database name which you created just now.
  9. Click on Import to start the process.

For any Query you can reach Me from the following Medium.

Stay tuned till the next blog

If you Want to Connect with Me:

Linkedin: https://www.linkedin.com/in/mayank-chourasia-38421a134/

Twitter: https://twitter.com/ChourasiaMayank.

Google Cloud Google Developers MySQL Avocado @GoogleCloudSQL

--

--

Mayank Chourasia

Hey, My name is Mayank Chourasia. Currently I am working on SAP Utilities as a SAP ABAP Developer. I had written a blogs on SAP ISU, SAP ABAP, Google Cloud .