1
votes

I can't connect Google Cloud SQL from GCE even I added public IP (external IP) of my GCE instance as a authorized network. It works when I add "0.0.0.0" into authorized network. Obviously I don't want to do that. The authorized network setting may be the cause. But I can't find out it. Does anyone know about this.

I'm using Google Cloud SQL version 2 beta. I am trying to connect from GCP cloud console. Although it may be not necessary, I changed external IP setting from ephemeral to static but it didn't work.

mysql -u root -p -h xxxx <--- I can login normally if I add "0.0.0.0" into authorized network. 

I've double checked this same question..

Linking Google Compute Engine and Google Cloud SQL

1. Ensure your Cloud SQL instance has an IPv4 address.
2. Find out the public IP address of your GCE instance and add it as an authorized network on your Cloud SQL instance.
3. Add a MySQL username and password for your instance with remote access.
4. When connecting from GCE use you standard MySQL connection system (e.g. mysqli_connect) with the username and password you just set up, connecting to the IPv4 address of your Cloud SQL instance.

Edit 1

I noticed this description.

Note: Connecting to Cloud SQL from Compute Engine using the Cloud SQL Proxy is currently available only for Cloud SQL Second Generation instances.

https://cloud.google.com/sql/docs/compute-engine-access

Does it mean that I have to use the Proxy..?


Edit 2

$ mysql -u root -p -h (Cloud SQL Instance's IP)
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '(Cloud SQL Instance's IP)' (110)

Edit 3

Does it mean that I have to use the Proxy..?

According to the official document as Vadim said, Cloud SQL Proxy seems to be optional but it sounds better for security, flexibility and also the price. (static IP will be charged. However, the proxy setting may be complicated for me..)

https://cloud.google.com/sql/docs/compute-engine-access

If you are connecting to a Cloud SQL First Generation instance, then you must use its IP address to connect. However, if you are using a Cloud SQL Second Generation instance, you can also use the Cloud SQL Proxy or the Cloud SQL Proxy Docker image.


Edit 4

I found the reason... I was stupid... I tried connect from Google Cloud Shell but that was not my gce instance. It works when I try to connect from my gce instance.

1

1 Answers

2
votes

Did you add the public IP of the GCE VM under authorized networks?

From your post:

2. Find out the public IP address of your GCE instance and add it as an   authorized network on your Cloud SQL instance.

The official documentation is here: https://cloud.google.com/sql/docs/external#appaccessIP