cloud-sql-jdbc-socket-factory icon indicating copy to clipboard operation
cloud-sql-jdbc-socket-factory copied to clipboard

Add examples on using unix sockets

Open enocom opened this issue 4 years ago • 2 comments

When connecting to a database, users sometimes get tripped up by the connection string. Our docs provide some guidance but could benefit from some examples.

For example, we say that connection strings should look like this:

jdbc:mysql:///<DATABASE_NAME>?cloudSqlInstance=<INSTANCE_CONNECTION_NAME>&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=<MYSQL_USER_NAME>&password=<MYSQL_USER_PASSWORD>

Immediately after we might add an example like:

jdbc:mysql:///mycooldb?cloudSqlInstance=/cloudsql/my-project:us-central1:mydb-instance&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=myuser&password=mypassword

Related to https://github.com/GoogleCloudPlatform/cloud-sql-jdbc-socket-factory/issues/547#issuecomment-881406057

enocom avatar Jul 16 '21 14:07 enocom

Your example here is incorrect - it would be cloudSqlInstance=my-project:us-central1:mydb-instance.

Personally, I don't think that the second example is any more helpful, as it's not clear to me which values I would need to replace. What might be helpful is more explanation immediately before the example, like we do in some of the Cloud Docs, that clarifies what values to replace. Something like:

Replace the following values:

  • INSTANCE_CONNECTION_NAME = your Cloud SQL's unique identifier, in the format PROJECT:REGION:INSTANCE
  • DATABASE_NAME = the name of the database you want to connect to
  • MYSQL_USER_NAME = your MySQL user for the Database
  • MYSQL_USER_PASSWORD = your MySQL user's password

kurtisvg avatar Jul 16 '21 16:07 kurtisvg

This is going to be addressed in some cleanup of our samples.

kurtisvg avatar Dec 02 '21 17:12 kurtisvg

Fixed in the samples. See https://github.com/GoogleCloudPlatform/java-docs-samples/blob/main/cloud-sql/postgres/servlet/src/main/java/com/example/cloudsql/ConnectorConnectionPoolFactory.java#L20.

enocom avatar Feb 16 '23 19:02 enocom