0

I have created a CloudSQL instance which was part of a VPC I have created. I'm able to connect to this CloudSQL using CloudSQL Proxy service. But I'm unable to connect to this instance using public IP of the instance though I added the firewall rule to this VPC.

The error I'm getting:

Unable to connect to host <public-ip-of-cloudsql>, or the request timed out.

Be sure that the address is correct and that you have the necessary privileges, or try increasing the connection timeout (currently 10 seconds).

MySQL said:

Can't connect to MySQL server on '<public-ip-of-cloudsql>' (4)

Following is the firewall rule I added and provided my home IP address in the blocked out area.

enter image description here

Please let me know if I'm missing something. I can provide more details if needed.

RC0993
  • 898
  • 1
  • 13
  • 44
Nandakishore
  • 981
  • 1
  • 9
  • 22
  • As per our discussion last night (and you should include this in the question as well), to confirm, you were able to connect to it via public IP BEFORE you added it to the VPC, right? It was only once you added it to the VPC that you stopped being able to connect to it? – Gabe Weiss Nov 11 '19 at 15:58
  • I just tried it again, created a MySQL Cloud SQL instance, with no private IP/VPC. Added my IP address, connected ok. Then edited the instance and added the Private IP checkbox, and assigned the instance to my default VPC, and I was still able to connect no problem. If you could, try that and confirm those things are true. If that process does work, then we need to know how you configured the VPC you created to put the Cloud SQL instance into, as it would appear that is the issue. – Gabe Weiss Nov 11 '19 at 21:10
  • With no private IP/VPC, it worked well for me too. First I created a VPC and then created a CloudSQL Instance and then added the VPC to this instance. Now when I'm trying to connect to CloudSQL, its failing. – Nandakishore Nov 12 '19 at 03:48
  • When you created the VPC, what options did you change from the defaults? What did you set in there? Need to know how you set that up in order to try to recreate the problem. Did you automatically create a subnet, or custom make one? If custom, when you created it, did you leave the IP address range alone as 10.0.0.0/9 or did you set something else? – Gabe Weiss Nov 12 '19 at 16:17
  • Also, when you added the Cloud SQL instance to the VPC, for the `Managed services network connection` piece, did you leave it at `Use an automatically allocated IP range` or did you pick the `Select the IP range` and put something in there? – Gabe Weiss Nov 12 '19 at 16:21
  • Oh NVM, saw that it started working. :) Glad it's working now! – Gabe Weiss Nov 12 '19 at 16:53

3 Answers3

0

These are the steps you should follow in order to connect to Cloud SQL using the public IP:

  1. Created a Cloud SQL instance, including configuring the default user.

Assuming you use a local client:

2.Install the client.

3.Configure access to your Cloud SQL instance.

4.Connect to your Cloud SQL instance.

You can find a detailed explanation here: Connecting MySQL client using public IP

marian.vladoi
  • 7,663
  • 1
  • 15
  • 29
0

If you are using the Cloud SQL proxy to connect via public ip, it requires port 3307 to be open to the address.

If you aren't using the Cloud SQL proxy to connect via public ip, you need to authorize your external IP.

kurtisvg
  • 3,412
  • 1
  • 8
  • 24
  • This will be true if CloudSQL was created which is not part of any VPC I believe. But if it's part of some VPC, then additional configuration might be required. – Nandakishore Nov 12 '19 at 03:57
0

I was able to connect CloudSQL which is part of a VPC by just adding the client IP address as Authorized networks.

It's weird, I tried many times before but couldn't succeed. It is working now. Thanks, guys for answers.

Nandakishore
  • 981
  • 1
  • 9
  • 22