I've seen other posts with the same issue here however none of the answers could help in my case. I have a Google SQLCloud 2nd generation database which I'm trying to make my Go Appengine app establish a connection to. I'm using go-sql-driver/mysql
At first I tried to connect the same way I used with the 1st generation just passing the project and instance names as parameters:
sql.Open("mysql", "root@cloudsql(project:instance)/database"
Then I've noticed from the Cloud Console and also from this post that the region is also required so my connection parameters now look like:
sql.Open("mysql", "root@cloudsql(project:uscentral1:instance)/database"
and also with password
sql.Open("mysql", "root:password@cloudsql(project:uscentral1:instance)/database"
Still not working
My last attempt was to connect using SSL as described on this post using the code provided from the drivers documentation:
rootCertPool := x509.NewCertPool()
pem, err := ioutil.ReadFile("/path/ca-cert.pem")
if err != nil {
log.Fatal(err)
}
if ok := rootCertPool.AppendCertsFromPEM(pem); !ok {
log.Fatal("Failed to append PEM.")
}
clientCert := make([]tls.Certificate, 0, 1)
certs, err := tls.LoadX509KeyPair("/path/client-cert.pem", "/path/client-key.pem")
if err != nil {
log.Fatal(err)
}
clientCert = append(clientCert, certs)
mysql.RegisterTLSConfig("custom", &tls.Config{
RootCAs: rootCertPool,
Certificates: clientCert,
})
sql.Open("mysql","root:password@cloudsql(project:uscentral1:instance)/database?tls=custom")
Also no luck.
At this point I'm just running out of ideas in what the issue could be. Has anyone done anything different than what most people did in order to get it working? At this point I'm not sure if the issue is with my code, with the driver or some configuration in the CloudSQL database.