MySQL Workbench cannot connect from home to Google Cloud SQL - google-cloud-sql

I cannot connect to my Google Cloud SQL database from my Macbook Pro using MySQL Workbench.
I have read the help file here:
https://cloud.google.com/sql/docs/mysql/admin-tools
I have added an authorized IP address for my IP per
https://cloud.google.com/sql/docs/mysql/configure-ip#add
I created a user for the database with it set to allow to connect from any host. I get the error "Can't connect to MySQL server on 'XX.XXX.XX.XXX' (60)
I have also attempted to telnet and get a consistent error that I am unable to connect to the remote host
As far as I know, I've followed all the steps but it really seems I'm getting blocked even before the server. I am trying to connect from home and I don't believe my home firewall is blocking things. I am wondering if there's something I need to open up on the GCE firewall but I have successfully connected to this database from other outside tools (e.g., Zapier).

Your best action right now would be to create a proxy with public IP address.
https://cloud.google.com/sql/docs/mysql/connect-external-app
This link will walk you through that process. If this doesn’t solve your issue, then taking your question to ServerFault (Stackoverflow sister site) might give you a better idea of how to fix your issue.

Related

GCP Can't Connect to MongoDB

This is my first attempt at deploying a Node.js application on a Google VM instance while connecting to MongoDB.
In MongoDB, I have whitelisted my IP address and the VM instance's IP address. When I start my server using Google Cloud Shell, I receive the following error:
op.cb(new error_1.MongoNetworkError(`connection ${this.id} to ${this.address} closed`));
^
MongoNetworkError: connection 1 to 34.71.95.215:27017 closed
I'm connecting on port 8080. The external IP is listed on my GCP instance page and when I ping it, it is up. IP: 34.68.254.120
When I whitelist 0.0.0.0/0 in Mongodb, the code runs successfully, and I can preview my app through GCP.
I created a new instance from scratch, and it also crashes with the same error.
ETA: In looking at the source code around the error message at:
...\node_modules\mongoose\node_modules\mongodb\lib\cmap\connection.js
it looks like a closed connection. The error message above spits out the IP address as the Iowa Google Data Center where my VM is housed.
I don't know what this means, but if you do, please let me know.
ETA2: I have 2 problems, and they may be connected. The first is that my VM server cannot connect to MongoDB. This should be simple -- whitelist the external IP address of my VM server. It does not work (I have to open MongoDB to 0.0.0.0/0 for it to connect).
The second is that I cannot connect to my server via the external IP address, regardless of whether MongoDB is connected or not. It "refuses to connect." I can do a web preview of my running server, though.
It seems the two may be connected somehow. I've rebooted my VM, but it did not fix anything. I whitelisted the error message IP address in MongoDB, but it did not help.
ETA3: Okay, it appears I have solved the whitelist to MongoDB issues. Through Cloud Shell, I asked my VM what the IP is. It is different than the one GCP tells me is the external IP. By adding this IP to the whitelist, I can connect between GCP VM and MongoDB. Whew. No idea why.
The VM's external IP address through my browser still gives me a cannot connect message, and when I use the new VM IP address I found through Cloud Shell, it gives me a "took too long to respond" message.
So I feel I have made progress. The remaining problem is accessing my server through Chrome.
Any suggestions on how I can investigate the issue further? I'm at a dead end. I believe the problem is likely simple given my inexperience.
Thanks!
Problem solved by a friend, for anyone in the future with this issue.
I had set up my GCP VM using Cloud Shell. I had housed my code by coping my repository through Cloud Shell. It turns out, this is more of a virtual interface with my VM, and the files are not physically on my VM. I needed to go through SSH, clone my repository there, and run my server through SSH. Cloud Shell was causing the problem.

Unable to connect PostgreSQL(pgAdmin 4) to the Google Cloud Platform

I have instance on Google Cloud Platform and I'm trying to connect it to the pgAdmin 4.
So here is my postgresql.conf
So I've tried the following:
I've wrote the instance ip as well as the username and password.
And I get the following error:
I've added my IP Address on cloud instance, but this didn't help as well.
Is there something else what I can try?
Posting this as a community wiki as this is based on the comments shared by #AdrianKlaver:
Given that you get a timeout expired error, which generally means a firewall blocked the connection, this is likely to be an issue on the port 5432 not being open to external access, so if you change that this might work.
NOTE: Just remember that you once you do this you will have opened the database to public access as determined by the IP's you allow in. Make sure your pg_hba.conf and role security are sufficient to deal with this. You can find more information on how to set this up by following both of this documenation links for Client Auth and to Create Roles

Connecting to Google Cloud SQL from my machine

I'm trying to connect to Google Cloud SQL from my machine (Ubuntu) using this command:
mysql --host='Public IP' --user='' --password
However, I'm getting this error:
ERROR 2003 (HY000): Can't connect to MySQL server on 'Public IP' (110)
I need any help resolving my issue.
First you need to let the Cloud SQL instance which IP addresses it can accept. You can do that without SSL by following the instructions here. However, to be more secure, I would recommend you using SSL. More info on that here.
Probably the easiest way to securely connect from your local machine to a public ip of a cloud SQL instance is to download and use the proxy, following the instructions here:
https://cloud.google.com/sql/docs/mysql/connect-admin-proxy
What you have to do is add a network to the public ip section, under the connections tab after selecting your Cloud SQL instance.
See Cloud SQL Connections Tab here
So, for the name input you put firstname-lastname kind of thing to denote whose ip it is. Then input your IP address 1.2.3.4/32 into the network input.
After doing so and saving you will be able to connect.
Yes, you can add SSL and use certificates. That is all best practice and what should be done for a production stack. But if this is just getting off the ground and in rapid development, that's all you need to do in the beginning.

Make PostgreSQL listen to Google Data Studio

I'm trying to connect one of my databases to Google Data Studio but I keep getting the following error:
Unable to reach the host.
I read the help page and already added the necessary IP addresses to the pg_hba.conf file this way:
hostnossl google_data_studio all 216.239.32.0/19 md5
That is just an example, but I have added all IP addresses required for the connection, 12 in total.
The connection description in Google's help pages shows these connections are non SSL (That's why I set it to hostnossl)
I've also restarted the postgresql service.
"Unable to reach the host" is a Google Data Studio error message, not a PostgreSQL message. PostgreSQL settings are irrelevant at this point. You are not reaching the server at all.
Since this just became a networking and settings issue for Google, I'm voting to close.

Google Cloud SQL VM refusing connection

I have been stuck trying to figure out why my Cloud SQL VM is refusing my connection from my machine (whom ip address I have added as a subnet). I cann SSH into the VM but i cannot access the VM from a browser to make SQLs. I have scoured the internet for days trying to find a fix but i cannot seem to get pass this point. My apache listens to port 80. Also Id like to add that I have been connecting to my Mysql db for months through php and making sqls so I do not believe the problem is with apache. However if it is please point me to where i should be looking.
It sounds like you have MySQL running on a GCE VM, not an actual CloudSQL instance (that is a different service from GCE). Is that right?
If so, then if you are trying to connect from your local machine directly to the mysql instance, you are probably getting blocked by the firewall. Go to the networks tab (under Compute Engine) on the cloud console and see what firewall rules you have enabled. You might need to add one for 3306 or whatever port you are using.