zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

【Bug解决】com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

mysqlBUGJDBC 解决 com Link failure exceptions
2023-09-14 09:15:11 时间

在使用mybatis连接MySQL数据库时,遇到这个问题:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

解决方案:
在mybatis-config.xml配置文件中,修改useSSL属性为false

      <dataSource type="POOLED">
          <property name="driver" value="com.mysql.jdbc.Driver"/>
          <property name="url"
                    value="jdbc:mysql://localhost:3306/mybatis?useSSL=false&amp;useUnicode=true&amp;characterEncoding=utf8"/>
          <property name="username" value="root"/>
          <property name="password" value="zxy100300"/>
      </dataSource>

原因分析:
SSL(Secure Sockets Layer 安全套接字协议),在mysql进行连接的时候,如果mysql的版本是5.7之后的版本必须要加上useSSL=false,mysql5.7以及之前的版本则不用进行添加useSSL=false,会默认为false,一般情况下都是使用useSSL=false,useSSL=true是进行安全验证,一般通过证书或者令牌什么的,useSSL=false就是通过账号密码进行连接。