Your Question

In order to secure our service, we need to use SSL certificate to connect to MySQL. How to use or config to do so?

The document you expected this should be explained

Expected answer

Comment From: github-actions[bot]

This issue has been automatically marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days

Comment From: MikyChow

I had the same issue here,Does anyone had a solution?

Comment From: dnyaneshwar89

I have the same issue, anyone have a solution?

Comment From: a631807682

You can have a try

https://pkg.go.dev/github.com/go-sql-driver/mysql#RegisterTLSConfig

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)
originMysql.RegisterTLSConfig("custom", &tls.Config{ // github.com/go-sql-driver/mysql
    RootCAs: rootCertPool,
    Certificates: clientCert,
})

gorm.Open(mysql.Open(dbDSN), &gorm.Config{})

Comment From: egorzot

What about postgres?