Cannot connect using gcloud

1,554 views
Skip to first unread message

Stephen Reilly

unread,
Feb 16, 2018, 8:58:56 AM2/16/18
to Google Cloud SQL discuss

I can list the databases in my Cloud SQL instance but I can't connect to it.


gcloud beta sql databases list --instance=dbinstance
NAME CHARSET COLLATION
information_schema utf8 utf8_general_ci
main utf8 utf8_general_ci
mysql utf8 utf8_general_ci
performance_schema utf8 utf8_general_ci


I can see my local machine being added to the authorisation list via the console. But it's failing to connect:


gcloud beta sql connect dbinstance --user=root
Whitelisting your IP for incoming connection for 5 minutes...done.
Connecting to database with SQL user [root].
Enter password:
ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (110)


It isn't configured to use SSL. Actually, this is a newly created instance so I'm happy to try any suggestions regardless of how drastic they are. I can connect in this way from the gcloud command line within the console.

Fady (Google Cloud Platform)

unread,
Feb 16, 2018, 5:54:45 PM2/16/18
to google-cloud...@googlegroups.com

Hello Stephen,


Since you are able to connect through cloudshell using the same gcloud commands, I suspect it is an issue within your local machine. Generally, when this error is logged, it means that the Cloud SQL instance did not whitelist (authorize) your IP, but could also be an underlying networking issue. In your message, you mentioned that you can see an IP address being authorized. It could be that your true IP address is different (computer behind proxy). You may find your IP through following both scenarios in this document . Then, to isolate the issue you may try the following:


  1. Manually add your computer’s IP address in the authorization list.

  2. use this command (gcloud uses the same client mysql command on your machine after the automatic whitelisting):


mysql -h <yourCloudSQLIP>  -u root -p


More troubleshooting steps can be found here [1] [2].You may also check these very similar issues at stackoverflow here [3] [4] . Furthermore,you may try other methods to connect using this guide. I hope this helps.

Stephen Reilly

unread,
Feb 19, 2018, 8:32:48 AM2/19/18
to Google Cloud SQL discuss
Thank you for your reply Fady. I have manually added my IP; which is the same viewed from both of the links you provided. Trying to connect with the mysql client yields the same response:

$ mysql -h 35.195.x.x  -u root -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '35.195.x.x' (110)

I followed the instructions in your first link [1] and have an ipv4 IP address for the database so the issues mentioned in the stackoverflow link shouldn't apply.

Regards,
Stephen

Carlos (Cloud Platform Support)

unread,
Feb 19, 2018, 1:02:14 PM2/19/18
to Google Cloud SQL discuss
Hi Stephen, 

Are you able to ping the IP address from your location?

If you install and run nmap against the IP of the server do you see the port opened? i.e.

nmap -Pn  w.x.y.z

Starting Nmap 6.47 ( http://nmap.org ) at 2018-02-19 18:00 UTC
Nmap scan report for....
Host is up (0.0014s latency).
Not shown: 999 filtered ports
PORT     STATE SERVICE
3306/tcp open  mysql



Stephen Reilly

unread,
Feb 19, 2018, 4:51:27 PM2/19/18
to Google Cloud SQL discuss
Hi Carlos. The ping responds successfully but the nmap returns:
nmap -Pn 35.195.x.x

Starting Nmap 7.01 ( https://nmap.org ) at 2018-02-19 20:53 GMT
Nmap scan report for 146.134.x.x.bc.googleusercontent.com (35.195.x.x)
Host is up.
All 1000 scanned ports on 146.134.x.x.bc.googleusercontent.com (35.195.x.x) are filtered

Nmap done: 1 IP address (1 host up) scanned in 201.43 seconds

When I try to specify port 3306 I get back:
nmap -p 3306 35.195.x.x

Starting Nmap 7.01 ( https://nmap.org ) at 2018-02-19 21:47 GMT
Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
Nmap done: 1 IP address (0 hosts up) scanned in 3.05 seconds

Kind regards,
Stephen

Carlos (Cloud Platform Support)

unread,
Feb 20, 2018, 1:08:32 PM2/20/18
to Google Cloud SQL discuss
Hi Stephen, 

You need to run the command using the flag "nmap  -Pn x.y.z.w".  If the command reports the port is being filtered, that probably means a firewall blocking the packets.

If you followed the steps provided by Fady, that should clear off the Google infrastructure. You should check your your local environment (antivirus firewall, etc).  To be sure you have whitelisted the appropriate IP on the Cloud SQL instance, you could use a 3rd party tool like this one. 
Reply all
Reply to author
Forward
0 new messages