Troubleshooting SSL Connections to Google Cloud SQL with Golang from Google App Engine
When attempting to establish a connection to Google Cloud SQL from Google App Engine using the go-sql-driver and SSL, developers often encounter a "certificate is valid for projectName:instanceName, not projectName" error. This issue arises when the ServerName property is not explicitly set when registering a custom TLSConfig with the mysql driver.
To address this problem, ensure you include the following steps in your code:
<code class="go">mysql.RegisterTLSConfig("custom", &tls.Config{ RootCAs: rootCertPool, Certificates: clientCert, ServerName: "projectName:instanceName", // <-- Added ServerName property })</code>
<code class="go">db, err := sql.Open("mysql", "user@cloudsql(project-id:instance-name)/dbname?tls=custom")</code>
By implementing these adjustments, you will successfully establish an SSL connection to your Cloud SQL instance from Google App Engine using Golang.
The above is the detailed content of How to Resolve SSL Connection Issues for Google Cloud SQL with Golang?. For more information, please follow other related articles on the PHP Chinese website!