MySQL升级8.0后连接不上数据库

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_26765193/article/details/84622445

将MySQL 升级为 8.0 后,无法连接到数据库,首先报错数据库驱动需要修改,其次要禁用 SSL 连接。

警告信息如下:

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. 

解决办法如下:

1,修改数据库配置文件

druid.driver=com.mysql.cj.jdbc.Driver
druid.url=jdbc:mysql://localhost:3306/babsport12?useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
druid.username=root
druid.password=123456

注意:

  • MySQL 8.0 中驱动包由 “com.mysql.jdbc.Driver” 改为 “com.mysql.cj.jdbc.Driver”
  • 要显式地禁用 SSL,useSSL=false
  • 添加时区 serverTimezone(MySQL jdbc 6.0 版本以上必须添加时区参数),UTC 为全球标准时间,但我们需要使用北京时区,设置serverTimezone=Asiz/Shanghai

2,修改 pom 配置

<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>8.0.12</version>
</dependency>

修改完成后,更新依赖。

以上步骤完成后,MySQL 数据库就可以正常连接了。

猜你喜欢

转载自blog.csdn.net/qq_26765193/article/details/84622445
今日推荐