Tuesday, March 3, 2020

[google-cloud-sql-discuss] Why my java program keeps connecting to Cloud SQL via cloudsqlproxy

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?

--
You received this message because you are subscribed to the Google Groups "Google Cloud SQL discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-cloud-sql-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-cloud-sql-discuss/74338290-51a9-4223-8003-7be1e8fc4dc3%40googlegroups.com.

No comments:

Post a Comment