Ends in
00
days
00
hrs
00
mins
00
secs
SHOP NOW

🎆 New Year Sale Extension - 25% OFF on ALL Reviewers to Start Your 2026 Strong with our New Year, New Skills Sale!

Back to Course

GCP PlayCloud Labs

0% Complete
0/0 Steps
  1. GCP PlayCloud Labs
  2. Guided Lab: How to Launch a GCP Compute Engine Linux Instance
  3. Guided Lab: Creating a VM Using Instance Templates
  4. Guided Lab: Creating and Managing Instance Groups in Compute Engine
  5. Guided Lab: Creating a Spot VM Instance
  6. Guided Lab: Configuring Shielded VM Options
  7. Guided Lab: Exploring Instance Metadata in Google Cloud
  8. Guided Lab: Vertically Scaling a VM Instance
  9. Guided Lab: Setting up a Web Server on a VM Instance
  10. Guided Lab: Creating a Custom Image from a VM Instance with Web Server in Google Cloud
  11. Guided Lab: Setting Up and Managing a Database on a VM Instance
  12. Guided Lab: Installing WordPress on an Ubuntu VM Instance with LEMP Stack
  13. Guided Lab: Reserving or Promoting a Static IP Address for a VM Instance
  14. Guided Lab: SSH Access to GCP VM Instance from Local Machine using SSH Key Pair
  15. Guided Lab: Creating a Cloud Storage Bucket
  16. Guided Lab: Hosting a Static Website in Google Cloud Storage Bucket
  17. Guided Lab: Protecting Data on Cloud Storage Bucket Against Accidental Delete and Overwrite Using Object Versioning
  18. Guided Lab: Creating a Cloud SQL Instance
  19. Guided Lab: Running SQL Commands in Cloud SQL Studio
  20. Guided Lab: Creating and Restoring Cloud SQL Backups
  21. Guided Lab: Integrating Cloud SQL Database instance with a VM instance
  22. Guided Lab: Connecting Cloud SQL Database with MySQL Workbench (Local)
  23. Guided Lab: Creating a Cloud NAT Gateway
  24. Guided Lab: Creating a Google Kubernetes Engine (GKE) Cluster
  25. Guided Lab: Connecting to a Kubernetes Engine Cluster
  26. Guided Lab: Deploying a Simple Web Application on GKE
Lesson 21 of 26
In Progress

Guided Lab: Integrating Cloud SQL Database instance with a VM instance

Description

In this lab, you will learn how to create and configure a Google Cloud SQL MySQL database and integrate it with a Compute Engine VM instance. You will provision a Cloud SQL instance, insert sample data using Cloud SQL Studio, configure networking to authorize the VM’s IP address, and finally verify connectivity by querying the data from the VM.

Prerequisites

This lab assumes you have experience creating a Compute Engine VM and Cloud SQL instances and are familiar with their basic components.

If you feel that your knowledge in this area is insufficient, we highly recommend taking the following labs to gain the necessary understanding:

Objectives

In this lab, you will:

  • Create a Cloud SQL MySQL instance
  • Add a user account and create a database
  • Insert sample data using Cloud SQL Studio
  • Configure networking to authorize the VM’s IP address
  • Create a VM instance in Google Cloud
  • Install MySQL client tools on the VM
  • Connect from the VM to the Cloud SQL instance and verify data

Lab Steps

Create a Cloud SQL Instance

1. In the Google Cloud Console, go to SQL → Create Instance.

2. Select MySQL as the database engine.

3. Configure the instance

  • Edition preset: Sandbox
  • Instance ID: Enter the desired instance ID.
  • Password: Set a secure password (e.g., Password@123)
  • Zonal availability: Single zone

4. Leave other configurations at their default values.

5. Once done, click Create instance.

Add a User Account

1. Once the instance is created, go to the Users tab.

2. Click Add user account.

3. Enter the desired User name and Password.

3. Click Add. A confirmation message will appear in the bottom‑left corner

Create a Database

1. Navigate to the Databases tab.

2. Click Create database.

3. Enter a Database name (e.g., EmployeesDB).

4. Once done, click the Create button.

Insert Sample Data Using Cloud SQL Studio

1. Navigate to the Cloud SQL Studio tab.

2. Select the database you created (EmployeesDB).

3. Enter the credentials for the user account you added earlier.

4. Click Authenticate.

5. Once authenticated, open the Untitled query editor.

6. Once authenticated, you’ll be ready to run SQL commands in Cloud SQL Studio. Begin by creating a new table within the EmployeesDB database to store employee records.

Paste the following SQL command into the query editor:

CREATE TABLE Employees ( ID INT PRIMARY KEY, Name VARCHAR(50), Age INT, Salary DECIMAL(10, 2) );

Click the Run button to execute the SQL command.

This creates a table named Employees with four columns: IDNameAge, and Salary

7. Insert Data into the Table

INSERT INTO Employees (ID, Name, Age, Salary)
VALUES (1, 'Jose Rizal', 25, 50000.00);

INSERT INTO Employees (ID, Name, Age, Salary)
VALUES (2, 'Andres Bonifacio', 25, 50000.00);

INSERT INTO Employees (ID, Name, Age, Salary)
VALUES (3, 'Emilio Aguinaldo', 25, 50000.00);

Click the Run button to execute the SQL commands.

These statements insert three employee records into the Employees table.

8. Query the Table

Run the following SQL command:

SELECT * FROM Employees;

Click the Run button to execute the SQL command.

This retrieves all rows and columns from the Employees table, displaying the data you inserted.

Create a VM Instance

1. In the Google Cloud Console, navigate to: Compute Engine → VM instances → Create Instance

2. Configure the VM with the following settings

  • Name: Enter your desired Instance name.
  • Machine type: e2-small
  • Boot disk:
    • Operating System: Ubuntu
    • Version: 24.04 LTS Minimal (x86/64, amd64 noble minimal image built on 2025‑12‑17)

3. Leave other configurations at their default values.

4. Click Create.

Install MySQL Client on the VM

1. Connect to your VM via SSH.

2. Update the package list:

sudo apt update

3. Install the MySQL client:

sudo apt install mysql-client -y

Note: The installation may take a few minutes. Wait until the process completes fully before moving to the next step.

Configure Networking for VM Access

1. In the Cloud SQL instance details page, go to Connections → Networking.

2. Under Authorized Networks, add the external IP address of your VM instance.

  • This allows the VM to connect to the Cloud SQL database via public IP.

3. Save the configuration.

Connect from VM to Cloud SQL

1. From your VM SSH terminal, connect to the Cloud SQL instance using the DB Instance’s public IP and user credentials:

sudo mysql -h 34.171.160.215 -P 3306 -u admin -p

2. Enter the password when prompted.

3. Switch to the database:

USE EmployeesDB;

4. Query the sample data:

SELECT * FROM Employees;

Congratulations! You have successfully created a Cloud SQL MySQL instance, added a user account, created a database, and inserted sample data using Cloud SQL Studio. You then configured networking to authorize your VM’s IP, created a VM instance, installed the MySQL client, and connected from the VM to verify the data. This workflow demonstrates how to integrate managed databases in Cloud SQL with Compute Engine VMs, enabling applications running on VMs to interact seamlessly with Cloud SQL.

Skip to content