Connecting to multiple instances of CloudSQL using Cloud sql proxy?

I am trying to use sql cloud proxy to connect to two different cloud sql instances ...

In the docs, I found a line about the Use -instances parameter. For multiple instances, use a comma-separated list. Use -instances parameter. For multiple instances, use a comma-separated list. but not sure how to do this. https://cloud.google.com/sql/docs/sql-proxy . I use the Google Container engine, and with a single instance of CloudSQL, it works fine:

 - name: cloudsql-proxy image: b.gcr.io/cloudsql-docker/gce-proxy:1.05 command: ["/cloud_sql_proxy", "--dir=/cloudsql", "-instances=starchup-147119:us-central1:first-db=tcp:3306", "-credential_file=/secrets/cloudsql/credentials.json"] volumeMounts: - name: cloudsql-oauth-credentials mountPath: /secrets/cloudsql readOnly: true - name: ssl-certs mountPath: /etc/ssl/certs 

But for a few, I tried the -instances section as such:

 -instances=starchup-147119:us-central1:first-db,starchup-147119:us-central1:second-db=tcp:3306 and -instances=starchup-147119:us-central1:first-db=tcp:3306,starchup-147119:us-central1:second-db=tcp:3306 

but they all give various errors; ECONNREFUSED 127.0.0.1:3306 , ER_DBACCESS_DENIED_ERROR and ER_ACCESS_DENIED_ERROR

Any help is much appreciated!

+5
source share
1 answer

You cannot have two databases hosted on the same TCP port. Instead, specify the ports for each database in a comma-separated list:

 -instances=project:region:db=tcp:3306,project:region:db-2=tcp:3307 

I used 3306 and 3307 here, but you can use any ports you want! Make sure the rest of the configuration of your container supports communication between nodes in these ports (maybe this is true by default, I do not use GKE).

Most mysql drivers connect to port 3306 by default, but have a way to specify a different port. You will need to configure the code to connect to another port that you selected for the second database.

+6
source

Source: https://habr.com/ru/post/1260301/


All Articles