问题提出

web应用中连接mysql数据库时后台会出现这样的提示:
Establishing SSL connection without server’s identity verification is not recommended. According to MySQL 5.5.45+,
5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn’t set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to ‘false’. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.

连接失败原因

原因是MySQL在高版本需要指明是否进行SSL连接。

1
2
3
4
5
6
7
8
9
SSL协议提供服务主要:   
1)认证用户服务器,确保数据发送到正确的服务器;    .
2)加密数据,防止数据传输途中被窃取使用;
3)维护数据完整性,验证数据在传输过程中是否丢失;

当前支持SSL协议两层:
SSL记录协议(SSL Record Protocol):建立靠传输协议(TCP)高层协议提供数据封装、压缩、加密等基本功能支持
SSL握手协议(SSL Handshake Protocol):建立SSL记录协议用于实际数据传输始前通讯双进行身份认证、协商加密
算法、 交换加密密钥等。

idea比较新的版本的话,只有8.0通用连接mysql的驱动,没有5.7之类的
所以会出现idea会报错,5.7的mysql存在安全风险之类的信息提醒
这时候只需要找到idea的mysql的配置源

解决方法

在mysql连接路径URL里配置上以下信息即可

1
2
3
4
5
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.xx.xx:3306/xxxx?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false
username: root
password: root

有用信息为

1
useSSL=false