【MySQL&SSL&JAVA】关于MySQL开启SSL后,jdbc的配置

一、MySQL服务端配置

 

# vim   /etc/my.cnf

###########################################

[mysqld]

require_secure_transport = ON

ssl-ca                   = /var/lib/mysql/ca.pem

ssl-cert                 = /var/lib/mysql/server-cert.pem

ssl-key                  = /var/lib/mysql/server-key.pem

############################################

【MySQL&SSL&JAVA】关于MySQL开启SSL后,jdbc的配置_第1张图片

# mysql  -u root  -p"MyS|QL@123"

mysql>  ALTER USER 'root'@'%' REQUIRE SSL;

mysql> FLUSH PRIVILEGES;

mysql> exit

# systemctl restart mysqld 

 

【MySQL&SSL&JAVA】关于MySQL开启SSL后,jdbc的配置_第2张图片

【MySQL&SSL&JAVA】关于MySQL开启SSL后,jdbc的配置_第3张图片

 

二、java应用的jdbc配置

 

MySQL驱动

driverClassName=com.mysql.cj.jdbc.Driver

url=jdbc:mysql://xx.xx.xx.xx:3306/test?allowMultiQueries=true&useUnicode&characterEncoding=UTF-8&autoReconnect=true&useSSL=true&verifyServerCertificate=false&requireSSL=true

username=root

password=MySQL@123

 

MariaDB驱动

driverClassName=org.mariadb.jdbc.Driver

url=jdbc:mariadb://xx.xx.xx.xx:3306/test?allowMultiQueries=true&useUnicode&characterEncoding=UTF-8&autoReconnect=true&useSSL=true&trustServerCertificate=true&requireSSL=true

username=root

password=MySQL@123

 

关于证书信任设置

MySQL:    verifyServerCertificate=false

MariaDB:  trustServerCertificate=true

 

【MySQL&SSL&JAVA】关于MySQL开启SSL后,jdbc的配置_第4张图片

三、参考

 

How To Configure SSL/TLS for MySQL on CentOS7.x?

https://www.jianshu.com/p/d0bc851b9844

 

关于对MySQL开启SSL的理解

https://www.jianshu.com/p/4f5957c394db

 

MySQL的jdbc驱动 com.mysql.jdbc.Driver 和 com.mysql.cj.jdbc.Driver的区别 

https://www.cnblogs.com/liaojie970/p/8916568.html

https://blog.csdn.net/superdangbo/article/details/78732700

 

MariaDB Connector/J

https://mariadb.com/kb/en/library/about-mariadb-connector-j

https://github.com/MariaDB/mariadb-connector-j/blob/master/documentation/use-mariadb-connector-j-driver.creole

你可能感兴趣的:(MySQL)