1. 安装openssl
2.生成证书并设置权限
mysql_ssl_rsa_setup --datadir=/data/database/mysql
ca-key.pem
ca.pem
client-cert.pem
client-key.pem
private_key.pem
public_key.pem
server-cert.pem
server-key.pem
权限设置 chown mysql:mysql /data/database/mysql -R
3.开启ssl配置
[root@ ~]
ssl-ca=/data/sqldata/ca.pem
ssl-cert=/data/sqldata/server-cert.pem
ssl-key=/data/sqldata/server-key.pem
4.验证mysql是否开启ssl
show global variables like ‘%ssl%’;
5.创建开启ssl用户并赋予权限
CREATE USER ‘admin’@’%’ IDENTIFIED BY ‘123456’ REQUIRE SSL; GRANT ALL PRIVILEGES ON . TO ‘admin’@’%’’ IDENTIFIED BY ‘123456’ WITH GRANT OPTION; FLUSH PRIVILEGES;
6.基于mysql登录并验证用户是否开启ssl
登录
mysql -h ip -uadmin -p --ssl-cert=/data/sqldata/client-cert.pem --ssl-key=/data/sqldata/client-key.pem
验证
status;
7.基于 ca.pem证书生成java客户端可识别的证书密码
keytool -importcert -alias tmsMySQLCACert -file ca.pem -keystore truststore -storepass 123456
8.java客户端设置
jdbcurl: jdbc:mysql://ip:3306/data?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&verifyServerCertificate=true&requireSSL=true&sslMode=verify_ca&trustCertificateKeyStoreUrl=file:C:/Users/20445/IdeaProjects/certificate/truststore&trustCertificateKeyStorePassword=123456
注意事项
使用过程中注意驱动使用的TLS版本是否是mysql数据库支持的版本
查看数据库tls支持的版本
SHOW GLOBAL VARIABLES LIKE ‘tls_version’;
|