0

enter image description here

I have created a very simple cloud sql database. It is a second generation mysql.

Form my other vm instance within the same project, I can ping this sql server with no issue

> ping 104.154.107.11                                                                     
PING 104.154.107.11 (104.154.107.11) 56(84) bytes of data.                                                                               
64 bytes from 104.154.107.11: icmp_seq=1 ttl=48 time=128 ms                                                                               
64 bytes from 104.154.107.11: icmp_seq=2 ttl=48 time=126 ms                                                                               
64 bytes from 104.154.107.11: icmp_seq=3 ttl=48 time=126 ms                                                                               
^C                                                                                                                                         
--- 104.154.106.111 ping statistics ---                                                                                                    
3 packets transmitted, 3 received, 0% packet loss, time 2002ms                                                                             
rtt min/avg/max/mdev = 126.789/127.307/128.309/0.708 ms    

The ping returns OK.

However if I try to connect using mysql client, I had a timeout

$ mysql --host=104.154.107.11                                                           
ERROR 2003 (HY000): Can't connect to MySQL server on '104.154.107.11' (110) 

Apparently private IPs are not allowed to add to authorised network. What do I need to do to fix the connectivity?

1

To connect from a VM to a Cloud SQL instance, you will need to authorize the public IP address of the VM instance.

As your screenshot shows no network is listed in Authorized network section. Click on Add network button, enter external IP address of your VM instance in Network field, click on Done, then Save it. Now you should be able to use mysql client from within your VM to connect to your Cloud SQL instance.

| improve this answer | |
  • I guess there is a gap in my understanding: why the gcp vm instance is not considered part of an 'internal network' from the cloud sql point of view? They both belongs to the same project? Any pointer/resource is appreciated. – Anthony Kong Feb 12 '17 at 23:26
  • Cloud SQL instances are protected by two levels of access controls: 1. Instance-level access, 2. Database access. Although your both SQL instance and VM are belong to the same project, but they are not on the same private network. Thus, they have to communicate via their external IP addresses. Instance-level Access Control helps to protect SQL instances against unauthorized login attempts. For more information, please visit this article. – Kamran Feb 12 '17 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.