Wednesday, March 4, 2020

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

If you're running this locally, Cloud SQL proxy will be used then.

https://cloud.google.com/sql/docs/mysql/connect-app-engine#best_practices_other_information
https://cloud.google.com/sql/docs/mysql/connect-app-engine#connecting_to
https://cloud.google.com/sql/docs/mysql/connect-app-engine#connecting_to


On Wednesday, March 4, 2020 at 9:30:55 AM UTC-5, Khanh Phan wrote:

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/a5955c67-9bbe-4974-98cd-5c9fa04c7185%40googlegroups.com.

No comments:

Post a Comment