How to use TLS 1.2 with MySql Go driver?

WBOY
Release: 2024-02-10 09:40:09
forward
660 people have browsed it

如何将 TLS 1.2 与 MySql Go 驱动程序一起使用?

php Xiaobian Youzi will introduce you to how to use TLS 1.2 with the MySQL Go driver in this article. TLS 1.2 is a secure transport protocol used to protect the security of network communications. When using the MySQL Go driver to connect to a database, enabling TLS 1.2 can improve the security of data transmission. This article will detail how to configure and use TLS 1.2 with the MySQL Go driver to establish a secure database connection. Following the guidance of this article, you will be able to easily use TLS 1.2 with the MySQL Go driver to protect your data and communications.

Question content

We must use tls1.2 to connect to our mysql server. In our java application we are using the following jdbc url -

jdbc:mysql://xxxx-001-dev.cluster-xx-2.rds.amazonaws.com/bats?**enabledtlsprotocols=tlsv1.2**
Copy after login

I am unable to achieve a similar configuration when connecting to mysql in our go application -

cfg1 := mysql.config{ user: "admin", passwd: "xxxxxxx", net: "tcp", addr: "xxxx-001-dev.cluster-xx-2.rds.amazonaws.com:3306", dbname: "xxxx", allownativepasswords: true, } sql.open("mysql", cfg1.formatdsn())
Copy after login

I tried adding the following statements. But it doesn't help, it throws the following error -

// enabledtlsprotocolstlsv1.2 cfg1 := mysql.config{ user: "admin", passwd: "xxxxxx", net: "tcp", addr: "xxxx-001-dev.cluster-xx-2.rds.amazonaws.com:3306", dbname: "xxxx", allownativepasswords: true, } cfg1.tls.minversion = tls.versiontls12 cfg1.tls.maxversion = tls.versiontls12 sql.open("mysql", cfg1.formatdsn())
Copy after login

mistake-

panic: runtime error: invalid memory address or nil pointer dereference [signal 0xc0000005 code=0x1 addr=0xf8 pc=0x64ac21] goroutine 1 [running]: main.main() C:/cmb-mmt/chp-schema-validation/main.go:28 +0x61
Copy after login

We are using the 5.7.12 mysql version

Solution

The following code solves this problem. and i am able to connect to mysql successfully.

cfg1 := mysql.Config{ User: cfg.Db.Dev.User, Passwd: cfg.Db.Dev.Pass, Net: "tcp", Addr: "cxx-cxxx-auroramysql-001-dev.xxxxxxxxx.us-west-2.rds.amazonaws.com:3306", DBName: "xxxx", AllowNativePasswords: true, TLSConfig: "skip-verify", TLS: &tls.Config{MinVersion: tls.VersionTLS12, MaxVersion: tls.VersionTLS12}, }
Copy after login

The above is the detailed content of How to use TLS 1.2 with MySql Go driver?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!