0

I am running MySQL on Ubuntu. mysql cli, as does http://localhost/phpmyadmin, but I cannot connect using java.sql.DriverManager.getConnection:

java.net.SocketException: Network is unreachable (connect failed)

ps tells me the service is running

/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid

The file /etc/mysql/my.cnf includes /etc/mysql/mysql.conf.d/ which contains another my.cnf which contains

[mysqld]
port = 3306

Using the cli, show variables like 'skip_networking' is OFF.

netstat -l | grep sql indicates a UNIX domain socket is listening, but nothing on TCP for sql.

Is this why jdbc can't connect?

How do I fix it?

spraff
  • 2,458

1 Answers1

0

Check using netstat whether port 3306 is listening or not.

Verify also that the bind-address is set to the Ethernet interface address (or "*") and not to the localhost address (this is the new default that replaces skip-networking, and very likely the source of your problems).

If the line is not present at all it should go with that default and work, so commenting the line is also good.

On some systems, localhost and 127.0.0.1 have different meanings; namely the former indicates a UNIX connection, the latter a TCP connection. I had this happen to me once, but no longer remember what system it was.

Ensure that the Java socket connection does connect to your server address. In a pinch, try using the command line MySQL to connect to the server using the --host parameter to force a TCP connection.

Finally, just to be sure, iptables -L -n should tell you whether the connection might be firewalled.

LSerni
  • 8,620