java工程连接远程MySQL数据库报错:Communications link failure due to underlying exception
来源:互联网 发布:mac全屏截图快捷键 编辑:程序博客网 时间:2024/06/07 01:55
在开发项目工程时,工程之前都是连接到局域网的测试数据库,运行没有问题。但是由于需要将项目部署到外网的服务器上,同时mysql数据库也是搭建在外网的服务器上,
当进行本地开发时,由于电脑是连接在本地的局域网内,需要连接到外网的数据库上,于是就遇到了问题:
com.mysql.jdbc.CommunicationsException: Communications link failure due to underlying exception:
** BEGIN NESTED EXCEPTION **
com.mysql.jdbc.CommunicationsException
MESSAGE: Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Connection reset
STACKTRACE:java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)
at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)
at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)
at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:1910)
at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2304)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2803)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1573)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1665)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3170)
at com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2436)
at com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)
at com.mysql.jdbc.Connection.<init>(Connection.java:1531)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
……** END NESTED EXCEPTION **
Last packet sent to the server was 203 ms ago.
STACKTRACE:
从错误可以看出,应该是数据库连接问题,于是各种谷歌、百度,终于解决问题:
1.首先要确保你能连接上远程数据库:如果远程服务器所在的电脑连接了路由器或是交互机则需要进行相应的端口映射
2.数据库连接测试没有问题后,找到mysql路径下的my.ini文件,然后再在[mysqld]下添加
wait_time=172800
interactive-timeout=172800
3.重启下mysql服务
- java工程连接远程MySQL数据库报错:Communications link failure due to underlying exception
- Mysql报错!Communications link failure due to underlying exception
- 解决“连接数据库是老是报Communications link failure due to underlying exception”
- DBCP Mysql报错!Communications link failure due to underlying exception
- Communications link failure due to underlying exception
- Communications link failure due to underlying exception
- Communications link failure due to underlying exception:
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- 解决MySQL连接超时Communications link failure due to underlying exception
- Communications link failure due to underlying exception: ** BEGIN NESTED EXCEPTION **
- C++——spfa和dijkstra算法模板
- WinCE下使用GPIO中断功能
- C++Primer第五版 第七章习题答案(11~20)
- Unity3d multi-object not supported的错误
- php下载模块生成代码
- java工程连接远程MySQL数据库报错:Communications link failure due to underlying exception
- 【Cyril的二级c++笔记】开篇
- windows下DokuWiki环境搭建
- Dragger2入门
- web前端性能优化
- BZOJ1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 后缀数组
- ZooKeeper-3.4.9集群安装配置及注意事项
- 接口回调----点击item中的ImageView,在Activity中显示dialog
- DialogFragment使用记录