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:
- Guided Lab: How to Launch a GCP Compute Engine Linux Instance
- Guided Lab: Setting Up and Managing a Database on a VM Instance
- Guided Lab: Creating a Cloud SQL Instance
- Guided Lab: Running SQL Commands in Cloud SQL Studio
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: ID, Name, Age, 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.