0

I can connect to MySQL if the code is:

conn = DriverManager.getConnection(
                "jdbc:mysql://localhost/db","root", "test");

but as soon as I change it to one of these (first is my IP Address)

conn = DriverManager.getConnection(
                "jdbc:mysql://82.41.85.161/db","root", "test");

conn = DriverManager.getConnection(
                "jdbc:mysql://127.0.01/db","root", "test");

It takes a while for something to happen, and all that does happen is a lack of connection.

SQLException: Communications link failure

I've tried changing the bind address in the CNF file and putting a "#" in front of it but nothing happens. I'm currently working purely in "MySQLWorkbench" and the end goal here is to actually connect from another computer to this database. Any help would be much appreciated.

2
  • Did you restart MySQL after changing the cnf file? Commented Jan 22, 2016 at 10:42
  • Its already there and hope it will work for you sure : stackoverflow.com/questions/14779104/… Commented Jan 22, 2016 at 10:50

4 Answers 4

1

You need to ensure that MySQL is set up to allow remote connections, and that your port is accessible. Users in the database can also be allowed/banned from being accessed externally.

Sign up to request clarification or add additional context in comments.

3 Comments

Users in the database can also be allowed/banned from being accessed externally. In that case there should be an error returned by mysql, not a connection failure
That is true, I didn't consider that.
I've allowed remote connections, but now it says: Check your SSH connection settings and whether the SSH server is up. Error: timed out
1
127.0.01

Is invalid. It should be

127.0.0.1

if localhost works fine there is usually never any reason for 127.0.0.1 not to work.

As far as the other one is concerned i'm sure your public interface does not allow mysql port access.

Comments

0

you forgot a dot here:

conn = DriverManager.getConnection(
                "jdbc:mysql://127.0.01/db","root", "test");

you should try this one:

conn = DriverManager.getConnection(
                "jdbc:mysql://127.0.0.1/db","root", "test");

Comments

0

First, you have a typo while setting the address in you connection to the loopback address. It should read 127.0.0.1 not 127.0.01.

conn = DriverManager.getConnection("jdbc:mysql://127.0.01/db","root", "test");

Secondly, remote access to MySQL database servers is disabled by default for security reasons. You must tell your server to bind itself to a given IP address and listen for connections.

For this you must edit your my.cnf file, which you might find in one of the following locations:

/etc/my.cnf
/etc/mysql/my.cnf
$MYSQL_HOME/my.cnf
[datadir]/my.cnf
~/.my.cnf

Alternatively you can use find to locate the file you want to edit:

$ find / -iname "my.cnf" -print 2>/dev/null
/etc/mysql/my.cnf

Then edit the my.cnf and add the following:

bind-address    = 82.41.85.161

Make sure that the line skip-networking is commented by using # before it like this: #skip-networking

Also verify that your firewall isn't blocking connections on port 3306 by using iptables -L -n | grep :PORT.

Finally restart mysql with /etc/init.d/mysql restart.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.