I am trying to connect to mysql
database using jdbc
in my java
program. I am using a RHEL 6 machine to connect to the mysql database. I have opened the port 3306 in this machine and if I do, mysql -u root -p
the mysql database connects.
If I do, mysql -h servername.edu -u root -p
the mysql database connects.
From my java program,
String url = "jdbc:mysql://localhost:3306/";
Works.
Now, if I change the localhost to servername, it doesn't work.
String url = "jdbc:mysql://server.com:3306/";
I get the error as,
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure to remote databse
Before posting the question, I did a fair bit of research on this exception from here.
I have setup the my.cnf
file correctly and I do not see an issue in that file. What am I missing here? The normal ping
to the server works fine as well.