Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
But no luck !

This shows port 0

netstat -tlnp doesn't show mysql at all

/etc/my.cnf 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 Also

# 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 ?

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
Alright. Will try this I also checked the mysql.user table. (Please see above). Could that be relevant ? – RN. Apr 3 '10 at 14:24
Linking my second related question here… – RN. Apr 3 '10 at 15:00
The solution turned out to be adding the port to my.cnf. Which in turn removed --skip-networking. T – RN. Apr 4 '10 at 16:08

The MySQL server is pre configured.

That is almost the same as not configured. Security will be bad, SQL MODE will be bad, performance will be bad, it's just not ready for production nor testing.

Just start reading the manual and create a good configuration. And don't forget the backups, mysqldump needs tweaking as well. By default, it doesn't backup views, stored procedures and events. Don't count on them unless you have tested your backups.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.