why my java keeps trying to connect to cloud sql via cloudsqlproxy?

75 visualizzazioni
Passa al primo messaggio da leggere

Khanh Phan

da leggere,
4 mar 2020, 09:30:4704/03/20
a Google Cloud SQL discuss

My Google Cloud mySQL is setup and running. In the user table, I have created id=test and allowed it to connect from % (any host)

I have a small Java program

Properties dbcpProperties = new Properties();

String CLOUD_SQL_CONNECTION_NAME = "google_project:us-central1:instance";

dbcpProperties.put("driverClassName","com.mysql.jdbc.Driver");

dbcpProperties.put("url",
        String.format(
            "jdbc:mysql://google/%s?socketFactory=com.google.cloud.sql.mysql.SocketFactory"
                + "&cloudSqlInstance=%s", DB_NAME, CLOUD_SQL_CONNECTION_NAME));

dbcpProperties.put("username", DB_USER);
dbcpProperties.put("password", DB_PASS);

try {
      BasicDataSource dataSource = (BasicDataSource) BasicDataSourceFactory.createDataSource(
          dbcpProperties);
      System.out.println("UPN Data source succesfully created.");
    } catch (Exception e) {
      System.out.println("FATAL ERROR: Couldn't create new Data source.");
      throw new RuntimeException(e);
    }

Everytime I run it, it complains Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'test'@'cloudsqlproxy~myipaddress' (using password: YES)) at org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) at org.apache.commons.dbcp.BasicDataSource.getLogWriter(BasicDataSource.java:1098) at org.apache.commons.dbcp.BasicDataSourceFactory.createDataSource(BasicDataSourceFactory.java:350) at test.Test.connect2CloudMySQL2(Test.java:1345) ... 6 more

But if I allowed user test to connect from any cloudsqlproxy~%, then it works

Why does it insists on using cloudsqlproxy ? How can I disable that?

Katayoon (Cloud Platform Support)

da leggere,
4 mar 2020, 12:42:2104/03/20
a Google Cloud SQL discuss
Hi Khanh, 

Cloud SQL proxy is needed to connect securely to Cloud SQL. In all scenarios to connect to a Cloud SQL instance a proxy is used unless you whitelist the IP address of the external client to the Cloud SQL instance or using App Engine/Cloud functions otherwise. 


Khanh Phan

da leggere,
4 mar 2020, 13:45:2404/03/20
a Google Cloud SQL discuss
I have another instance which is working.  By that I means, there's no cloud sql proxy in the middle; the same java code can connect to it.
To simulate the issue on the working instance, I intentionally changed mysql user name in the java call... and then i got the same message 
(Access denied for user 'test-'@cloudsqlproxy~someipaddress (using password: YES))

What's weird here is (1) it's still referring to a mysql account that i never setup
(2) the ip-address is not known to me and it's not active

any idea?

Jad El Houssami

da leggere,
6 mar 2020, 12:22:5806/03/20
a Google Cloud SQL discuss
Hello Kahnh,

I see that there is already another thread which appears to be a duplicate of this one.

As the thread is presently active, I would ask you to continue communicating there to avoid confusion and to better track the progress in a single point of contact.

We appreciate your understanding.
Rispondi a tutti
Rispondi all'autore
Inoltra
0 nuovi messaggi