1

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: java.net.ConnectException: 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 !

SHOW GLOBAL VARIABLES LIKE 'PORT';
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/mysqld.pid --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';
+-----------+-------+
| HOST | USER |
+-----------+-------+
| 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 ?

2 Answers 2

1

Please note the --skip-networking parameter

Yes, very likely the cause of the issue. Remove skip-networking and add "bind-address=127.0.0.1" 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.

3
  • Alright. Will try this I also checked the mysql.user table. (Please see above). Could that be relevant ?
    – RN.
    Apr 3, 2010 at 14:24
  • Linking my second related question here -serverfault.com/questions/129064/…
    – RN.
    Apr 3, 2010 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, 2010 at 16:08
0

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .