Mysql – Cant connect to MySQL server from Java application


This is on VPS\Centos server. The MySQL server is pre configured.

I am running the Java application on Tomcat

My Java web application is not able to connect to the MySQL server.

I get an error –
"Caused by: Connection refused"

I suspect this to be a configuration problem rather than a coding problem- hence I have posted this on ServerFault
And yes, The same web-app is able to connect to MySQL on a different linux box

This is the URL that I provided to my Java application (note- it assumes default port)

url = "jdbc:mysql://localhost/pickupgames"

My first suspicion was that I am running on a non-default port
So I tried to find the port where mySQL server is running

I tried every trick mentioned in How to check what port mysql is running on
But no luck !

This shows port 0

netstat -tlnp
doesn't show mysql at all

It has no port entry

telnet localhost 3306
Doesn't connect

And in case you are wondering if mysql server is running at all or not
It is
And I know for sure, because I have been able to login using the mysql command

# ps -ef|grep 'mysql'
root 31839 27662 0 00:49 pts/3 00:00:00 grep mysql
root 32452 1 0 Apr02 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe –skip-grant-tables –skip-networking
mysql 32504 32452 0 Apr02 ? 00:00:06 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –user=mysql –pid-file=/var/run/mysqld/ –skip-external-locking –socket=/var/lib/mysql/mysql.sock –skip-grant-tables –skip-networking

Please note the –skip-networking parameter
Does this have something to do with the issue ?

mysql> SELECT HOST, USER from mysql.user where user='admin';
| localhost | admin |

Does the above have any bearing ?

Any explanation why I cant connect to mysql server on port 3306 by telnet?

Or why it docent show up under netstat?

Any suggestion on whet I should try next ?

Best Answer

Please note the --skip-networking parameter

Yes, very likely the cause of the issue. Remove skip-networking and add "bind-address=" instead in my.cnf.

I guess java connects via network only and does not use socket connections, which is what you do with mysql cli tools.