问题描述
其他连接工具,本地连接服务器数据库,都可以。但是服务器上代码连接数据库,无法连接
log信息
com.zaxxer.hikari.pool.HikariPool.throwPoolInitializationException - HikariPool-1 - Exception during pool initialization.
com.mysql.cj.jdbc.exceptions.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 serve
解决思路
1.jdbc.Driver的版本
2.连接的参数
jdbc:mysql://192.168.0.1:3306/test?useUnicode=true&characterEncodeing=UTF-8&useSSL=false&serverTimezone=GMT
3重启数据库
service mysqld restart
4.访问的IP
有些数据库通过外网IP访问,内部访问的时候可以用127.0.0.1访问,修改访问url
url: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncodeing=UTF-8&useSSL=false&serverTimezone=GMT