GCE SQL proxy connecting to wrong sql ip

7/5/2019

I am having a strange issue with my GCE Proxy. I used to have a docker image with an application that would use the GCE proxy to connect to the mysql database(second generation). Everything worked fine, but I had to stop the services for like a month.

Now I need them back up and for some reason I am not able to connect to the dabase(configuration did not basically chang, and I am using the same docker image with the code)

On closer inspection I see in logs:

Caused by: java.sql.SQLException: Access denied for user 'my-usr'@'cloudsqlproxy~SOME_IP' (using password: YES)

The problem is, that the "SOME_IP" is not actually the sql instance IP and I have no idea from where that IP is coming from.

Does anyone have an idea on how to fix this issue?

I did try to:
-recreate the database user
-recreate the service account

Any advice is welcomed

-- Mihai
google-cloud-platform
google-cloud-storage
google-kubernetes-engine

1 Answer

7/6/2019

You can use Cloud SQL proxy to connect your mysql instance, see the step by step below:

  1. Download the proxy:

    wget https://dl.google.com/cloudsql/cloud_sql_proxy.linux.amd64 -O cloud_sql_proxy

  2. Make the proxy executable:

    chmod +x cloud_sql_proxy

  3. Using the proxy to connect to multiple instances

    ./cloud_sql_proxy -instances=yourProject:us-central1:myInstance=tcp:3306,yourProject:us-central1:myInstance2=tcp:3307 & mysql -u myUser --host 127.0.0.1 --port 3307

  4. Try to connect your database

    mysql -h127.0.0.1 -u$YOUR_CLOUD_SQL_USER -p$YOUR_CLOUD_SQL_PASSWORD

Hoping it helps you!

-- Le Khiem
Source: StackOverflow