Walker Holahan
Walker Holahan

Reputation: 87

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: Connection 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?

Upvotes: 4

Views: 40798

Answers (2)

Namhyeon Go
Namhyeon Go

Reputation: 673

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.

Upvotes: 2

Walker Holahan
Walker Holahan

Reputation: 87

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

Upvotes: 0

Related Questions