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

编程入门 行业动态 更新时间:2024-10-11 23:22:23

MySQL连接<a href=https://www.elefans.com/category/jswz/34/1771210.html style=异常:Communications link failure 解决方案"/>

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

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

  1. 首先确认数据库是否可以正常运行中并且可被连接。可以使用工具 Navicat 测试连接。
  2. 判断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,
  3. 检查数据库连接参数:在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

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

更多推荐

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

本文发布于:2024-02-24 14:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1695613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   解决方案   MySQL   Communications   failure

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!