cloud-sql-jdbc-socket-factory
cloud-sql-jdbc-socket-factory copied to clipboard
Add examples on using unix sockets
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
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 formatPROJECT:REGION:INSTANCEDATABASE_NAME= the name of the database you want to connect toMYSQL_USER_NAME= your MySQL user for the DatabaseMYSQL_USER_PASSWORD= your MySQL user's password
This is going to be addressed in some cleanup of our samples.
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.