换
jar
包、加?useSSL=false
,3306
加防火墙,都不能解决我的问题。最终我发现是我的LNMP
环境导致
错误提示
Response message:java.sql.SQLException: Cannot create PoolableConnectionFactory (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.)
解决办法
LNMP
默认3306
端口是DROP
的,需要把这一条记录删掉
查看端口
iptables -L -n --line-numbers
显示
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
2 ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 state RELATED,ESTABLISHED
3 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:22
4 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:80
5 ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:443
6 DROP tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3306
7 ACCEPT icmp -- 0.0.0.0/0 0.0.0.0/0 icmptype 8
第六行3306的状态是DROP的,也就是外网无法访问
删除这条记录:
iptables -D INPUT 6
到这里我的问题就解决了,也要确保 MySQL
的远程访问打开