Connecting to the Google Cloud SQL via the MYSQL client

Shalitha Lakruwan
3 min readAug 2, 2022

This article explains how to connect to cloud SQL to using the MYSQL client, which is installed on a compute engine instance.

Before you begin

You should activate two APIs in Google Cloud Console.

Menu → APIs & Services → Enabled APIs & Services

01) Compute Engine API

02) Cloud SQL Admin API

Step 01

Create a Compute Engine VM instance

Menu → Compute Engine → VM instance

  1. Click Create instance.
  2. Specify a Name for your VM. For more information
  3. Optional: Change the Zone for this VM.
  4. Select a Machine configuration for your VM.
  5. Optional: In the Boot disk section, click Change, Select a project and Open the image.
  6. In the Firewall section, Allow HTTP traffic or Allow HTTPS traffic.

7.To create and start the VM, click Create.

Step 02

Create a MySQL instance

Menu → SQL

  1. Click Create instance.
  2. Select MYSQL
  3. Specify an Instance ID & password.
  4. Select the Database version.
  5. To create and start the SQL instance, click Create.

Step 03

Connect MySQL instance to VM

Menu → SQL → Connections

  1. Click Add network.
  2. Specify a name
  3. Enter the External IP address of your VM in the Network box
  4. Click Done and Save buttons.

Step 04

Install & connect MySQL client on your VM

Menu → Compute Engine → VM instance

  1. Select your VM.
  2. SSH your VM.
  3. Run the following command in your shell
  • sudo apt-get install default-mysql-server
  • mysql -h INSTANCE_IP -u USERNAME -p

4. Enter the MYSQL password.

Well Done. 😀

--

--