开发者

Issue connecting to port 3306 for mysql application

The Java application I am working with is supposed to write its resulting data to a mysql database, but whenever I run it, I get the following exception:

com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

With the following cause:

Caused by: java.net.ConnectException: Connection refused

Naturally, my next step was to test the port that mysql was attempting to connect on (3306).

$ telnet localhost 3306 
Trying 127.0.0.1...
telnet: Unable to connect to remote host: Connect开发者_如何学Cion refused

My next step was to see if port 3306 was listening at all.

$ netstat -an|grep 3306
tcp        0      0 69.164.214.18:3306      0.0.0.0:*               LISTEN

So in summary, the port is listening but not accepting connections? I must admit, I do not know a whole lot about this, but does anybody know what is going on here?


Checklist:

  1. Firewall rule: If your server deny/not allow 3306 port, can not connect it.
  2. Bind Address: if your bind address are 127.0.0.1 in MySQL configuration, you must change to 0.0.0.0 in [mysqld] on /etc/mysql/my.cnf
  3. Restart Service: you have to run command 'service mysql restart'

Good Luck.


I figured it out. I needed to connect to mysql externally, but my program was trying to access it locally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜