Can't reach database server or port
SQLState - 08S01
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.

==========解决============
开始以为是数据库的配置问题,但是用mysql -hlocalhost -uroot -p却可以正常连接。
后来百度搜索,说是需要加参数:useSSL=false
因为我的mysql是用的docker起的服务,仍然报错,不能连接。
后来把localhost改成本机IP地址解决了:
jdbc:mysql://192.168.1.34/confluence?useSSL=false

参考:
https://blog.youkuaiyun.com/xiongshengwu/article/details/46981101
博主遇到通过Java JDBC连接MySQL Docker容器时出现'Can't reach database server or port'的错误。尝试使用mysql -h localhost -u root -p命令能正常连接,但Java程序连接失败。经过排查,发现解决方案是在URL中添加useSSL=false参数。然而,对于Docker内的MySQL服务,这样做仍然无效。最终,将localhost替换为Docker容器的IP地址(如192.168.1.34)成功解决了问题。

被折叠的 条评论
为什么被折叠?



