Jdbc连接Docker中mysql连接不上问题排查

1:docker中mysql跟宿主机做了端口映射,允许任意ip访问

2:本地Navicat 可以连接docker 中 mysql

3:jdbc连接不上 报错如下:

com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Could not create connection to database server.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_192]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_192]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_192]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_192]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:400) ~[mysql-connector-java-5.1.36.jar:5.1.36]
at com.mysql.jdbc.Util.getInstance(Util.java:383) ~[mysql-connector-java-5.1.36.jar:5.1.36]

 

4经过一些列排查 最终定位问题为mysql驱动包版本太低 不能驱动 高版本mysql,

old:

<dependency>

   <groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.36</version>
</dependency>

new:

<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.11</version>
</dependency>

 

升级mysql驱动包后成功连接上数据库



posted @ 2019-12-25 13:19  洞玄巅峰  阅读(5823)  评论(0编辑  收藏  举报