Skip to main content

Troubleshooting a Connection Issue with Cloud SQL

Hands-On Lab


Photo of Broadus Palmer

Broadus Palmer

Google Cloud Training Architect





Sometimes, you may face connectivity issues with your Cloud SQL instance, and it's important to know what to look for when troubleshooting. In this hands-on lab, we will discover a solution when troubleshooting a connection issue between a Compute Engine Instance and a Cloud SQL Instance.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Troubleshooting a Connection Issue with Cloud SQL

In this hands-on lab, we will troubleshoot a connection issue between a Compute Engine Instance and a Cloud SQL Instance.

Our team is having trouble connecting to the Cloud SQL instances in our project using the public IP. They have tasked us with troubleshooting the environment and fixing the problem. In the end, our team should be able to connect successfully to a Cloud SQL instance in the team's project.

Troubleshooting Connection Issues

To troubleshoot the connection issues, we will need to go through the following steps:

  1. Try to connect with the Cloud SQL instance from our Compute Engine Instance.
  2. Check to see if we can ping the IP address.
  3. Make sure that our IP address is an Authorized Network for the Cloud SQL network.
  4. Try to connect to the Cloud SQL instance again.

Create a Cloud SQL Instance

From the main console navigation, head over to SQL. Here, click on the CREATE INSTANCE and then choose MySQL. We want to fill the information out as follows:

  • Name: test-connection-instance
  • Root password: 12345
  • Database Version: MySQL 5.7

With everything set, click Create.

Create a Compute Engine Instance

With our instance created, go back to the main console. Here, head over to Compute Engine. On this page, click on Create. We will leave most of these items as their default, though, under Firewall, we will select Allow HTTP. Select Create.

Enable the Cloud SQL Admin API

Now, we need to enable the Cloud SQL Admin API. To do that, we need to go back to the main page once again. This time, we want to select APIs and Services. Here, click on Enable APIs and Services, then type in Cloud SQL Admin API. Finally, click Enable.

Add the Compute Engine Instance Public IP as an Authorized Network for Cloud SQL

Our next step is to add a compute engine instance to the public IP. To do that, from the main console navigation, select SQL. On this page, choose and copy the public IP for our instance.

Go back to the main console navigation, and this time select Compute Engine. Click on the test-connection-instance, then on edit, and then connectivity. Here, under Authorized Network, name the instance my_instance and paste the IP. Click Done and then Save.

SSH into the VM to Connect to Cloud SQL

To check our connection and make sure it is working correctly, from the main console navigation, head over to Compute Engine. Click on SSH. Once connected, we will use the command sudo apt-get update, then sudo apt-get install default-mysql-client -y.

Connect to the instance by using the command mysql -h "public ip of your cloud sql instance" -u root -p. Use the password we set up for our instance.

We are now connected.


Upon completing this lab, we are now able to troubleshoot connection issues with Cloud SQL. Congratulations on finishing this lab!