com.mysql.jdbc.CommunicationsException: Communications link failure
Last packet sent to the server was 0 ms ago.
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1070)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2104)
at com.mysql.jdbc.ConnectionImpl.(ConnectionImpl.java:729)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:298)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:283)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:171)
at com.jak.sandbox.hsm.HSMTest.testJDBC(HSMTest.java:35)
at com.jak.sandbox.hsm.HSMTest.main(HSMTest.java:24)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:452)
at java.net.Socket.connect(Socket.java:402)
at java.net.Socket.(Socket.java:309)
at java.net.Socket.(Socket.java:153)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:256)
at com.mysql.jdbc.MysqlIO.(MysqlIO.java:276)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2027)
... 7 more
After googling a lot and reading may forums finally found solution from Ubuntu Forums. Here is the deal
- By default MySQL 5.1 allows only local connection
- Remote connections should explicitly be turned on

So to allow TCP/IP connections just comment out the line bind-address = 127.0.0.1 and restart the server. Settings mentioned here opens up connection from any IP. So not might be a very good configuration if we think in terms of database administration or security. But for a developer like me, this suffices the requirement. Regarding database administration and security, let me not poke my nose and leave it upto smart database administrators.
[UPDATE - 22 July 2010 16:48] - Found same issue (rather default configuration) for JBoss too. When you run JBoss application server with default configuration, it will not be accessible over internet/intranet. It will be accessible only on localhost. To make it available over the internet/intranet, start JBoss with run -b 0.0.0.0 and it should work.
Cheers !!!
- Jay

