MySQL连接异常:Communications link failure 解决方案

您所在的位置:网站首页 网络错误号0 MySQL连接异常:Communications link failure 解决方案

MySQL连接异常:Communications link failure 解决方案

2024-07-12 10:30| 来源: 网络整理| 查看: 265

MySQL连接异常,报错:Communications link failure,可以采用如下方法解决:

首先确认数据库是否可以正常运行中并且可被连接。可以使用工具 Navicat 测试连接。判断MySQL版本兼容问题。程序中: mysql-connector-java:8.0.18版本driver-class-name:com.mysql.cj.jdbc.Driver(driver-class-name只有在8.0版本才能使用com.mysql.cj.jdbc.Driver,而8.0以下只能使用com.mysql.jdbc.Driver;而且8.0版本以上需要设置时区为:serverTimezone=GMT%2B8)使用命令select version()查看MySQL版本:5.7.39, 检查数据库连接参数:在application.properties 文件中,配置如下: spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8 spring.datasource.username=root spring.datasource.password=123456

经过多次尝试,发现出问题是在url配置中useSSL=true参数,MySQL在高版本需要指明是否进行SSL连接,MySQL5是不需要这个参数的。解决方案是:useSSL=false。即改成如下配置:

spring.datasource.url=jdbc:mysql://localhost:3306/mybatis_plus?serverTimezone=GMT%2B8&useSSL=false

自此,问题解决,数据库连接成功!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3