How to connect to google cloud sql instance from eclipse using App Engine? - mysql

I am trying to connect to google cloud sql instance from eclipse in my app engine connected android project.
So far i am able to connect to cloud sql instance using Class.forname("com.mysql.jdbc.Driver"). But it requires authorising my ip address in google cloud sql every time i want to use the instance hence making it unfeasible.
I know that while connecting from app engine i dont need to authorize my ip address. Bur for that i have to use GoogleDriver ie. Class.forname("com.mysql.jdbc.GoogleDriver").
But when i run my code it gives me ClassNotFoundException.
I am stuck at this situation for a long time. Please give me a proper solution to the problem

The GoogleDriver is only intended to be used when actually running on App Engine. When running from eclipse or the dev_appserver you will have to use the stock com.mysql.jdbc.Driver class, and you will have to authorize your IP address. A good example of this is shown in the documentation, which demonstrates how to choose in code which driver to use. Note the commented out line for connecting from your dev environment to Cloud SQL.
As an FYI don't forget to enable the connector for running on App Engine.

I have authorised 0.0.0.0/0 in access control in my cloud instance and now all the devices are able to connect to the cloud instance with stock mysql driver ie. com.mysql.jdbc.Driver without need to changing authorised network again and again in access control.
Still can't figure out to implement GoogleDriver but for now this solution will work.
If anyone find a more better and general way to connect to cloud instance please post your answer.

Related

MySQL Connection error Google Cloud

I deploy a node + sql application I made testes running the node app in my laptop using mysql database provided by google and the application was working fine (I needed to allow my ip address to connect) but when I deployed the application I started to receive timeout errors in my app. I solved the problem allowing any ip address to connect in my google cloud mysql instance but I not happy with this solution. Anybody can help to allow just the production node app server ip?
Thanks in advance.
If you want your API key to only be accessed from a certain IP, you can restrict it in the Developers Console.

ERROR 2003 (HY000): Can't connect to MySQL server on 'x.x.x.x' (110)

I'm trying to establish a basic mysql connection from a google compute engine instance in one project to a google cloud sql instance (2nd generation) in a different project.
I've done this many times before without any problem. You simply add the ip address of the google compute instance to the list of authorized networks for the google cloud sql instance. This has always worked in the past but it is not working now.
The only thing that I can think of which is different about this situation is that I've recently been experimenting with using the cloudsql-proxy to establish a connection from a different gce instance to the same google cloud sql instance. Could this be the problem? Perhaps the google cloud sql instance is getting confused by having to support both connection mechanisms?
I just need the connection to work. Is there a work-around?
There isn't a problem using both modes of connectivity simultaneously.
The only thing I can think of is that you are accidentally using an ephemeral IP addresses for your VMs instead of static, which means the VM may have a different IP address than you expect (after a restart, for example).
If that's not the case, please send a mail to cloud-sql#google.com with a little bit more information (project and database name, project/name/ip of your VM) so that we can figure out what's going on in the backend.

Cannot access Google Cloud SQL database from my App Engine

Last week I tried to setup Google Cloud for a NodeJS API and Cloud SQL database. Overall it works fine, but I can't access my Cloud SQL database. The authorization of the SQL database shows that all apps within the current project are granted to access the database. Unfortunality, this is not true. I need to granted the IP addresses of the instances from the App Engine. The IP adressess of the instances constantly changes after I deploy a newer version of the the API.
Does anybody have a solution to get access from the App Engine to the Cloud SQL database. It's very annoying to add constant the instance ip address to grant the database.
Sample here
Thank you in advance!
Jelle
I was going to suggest to assign a static IP to the app engine, but seems like it's not possible in App engine (it's possible in compute engine though). So lets tackle the root of the problem, you being unable to access cloud sql from App engine, are you sure you followed the instructions of the following link to the letter?
https://cloud.google.com/nodejs/getting-started/using-cloud-sql
This might solve your connection issue if you haven't.

Building a website on Google Cloud compute with cloudsql

I'm trying to move my dynamic website and database from my own VM's to the Google cloud. For the DB, I'm using the Google Cloud SQL, and for the website I made a host under compute.
The problem is, I can't seem to connect to the DB from the VM using an internal IP address. Somehow my Cloud SQL DB only has an external IP address.
I also have phpMyAdmin running on a compute VM, this machine can also only connect to the external ip address (this works, but I'm guessing is not very secure)
What am I doing wrong? Must I use the app engine instead for my website? I've done the training exercise but, to be honest, I have no clue what I was doing.
CloudSQL does not currently support private networks. You either need to connect via external IP or use CloudSQL proxy.
In order to increase security make sure to connect via SSL when using external IP.

Google cloud VM Instance DNS error

I am having a bit of an issue with the VM Instances on google cloud. I installed and set up apache and a website with it but now I am trying to configure a custom domain and when I try to add it in SSH I get the following error:
ERROR: (gcloud.dns.managed-zone.create) ResponseError: status=403, code=Forbidden, reason(s)=insufficientPermissions
message=Insufficient Permission
I have also tried the directions at the following https://cloud.google.com/appengine/docs/domain and am getting a 404 not found error on my domain. Any help would be greatly appreciated.
You say you are having an issue with a VM instance and are trying to set up a custom domain. Those two are in very different realms. VM instances are under Compute Engine (except for Managed VMs, which live under App Engine, but that is beside the point). Custom Domains are features just of App Engine.
What do you mean that you are trying to "add it in SSH"? Did you mean DNS? If so, see my answer below.
What command are you running to get ERROR: (gcloud.dns.managed-zone.create) ResponseError: status=403, code=Forbidden, reason(s)=insufficientPermissions message=Insufficient Permission?
The docs apply to App Engine, not Compute Engine. That you are getting a 404 error is no surprise if you don't also have a corresponding app running in App Engine.
If you are trying to create a DNS hostname for a web site hosted on a VM instance on Compute Engine, I recommend that you either (a) use a static IP address and a static A record pointing to it, or (b) use an ephemeral IP address and set up a dynamic DNS A records pointing to it. (I use freedns.afraid.org for my DDNS.)