2

I am trying to connect to MySQL database over a network. I have installed MySQL, and the service is running on the default port. I have also install the SQL connector to the jar file and added java JDK to the server machine. I am able to connect to my local database using the code:

private String dbUrl = "jdbc:mysql://localhost/DatabaseName";
private String dbClass = "com.mysql.jdbc.Driver";

But when I try and connect to it over the network, with the IP address (eg: 192.168.1.45):

private String dbUrl = "jdbc:mysql://192.168.1.45/DatabaseName";
private String dbClass = "com.mysql.jdbc.Driver";

I get the connection error:

Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure

Does anyone know what this issue is? Do I need to add a different address? I have added the default port with the address but cannot get it to work.

Thanks for any help.

1

3 Answers 3

3

By default, MySQL doesnt allow remote access and only allow local access. You will have to modify your /etc/mysql/my.cnf config (on Linux) with:

bind-address = 192.168.1.45 // Your Server IP address
# skip-networking // This should be commented .

See the whole procedure here.

Sign up to request clarification or add additional context in comments.

Comments

2
  1. Check the my.cnf [mysqld] settings for the parameters port, bind-address, socket, to make sure these aren't causing problems.
  2. Check the files /etc/hosts, /etc/hosts.deny to make sure everything is ok.
  3. Check firewall applications
  4. Check to make sure whatever directory mysqld's sockets are have the appropriate permissions.
  5. Check to make sure that security settings within the mysql database (user table) permit access from your remote host.
  6. Make sure you can telnet OK to localhost 3306, 127.0.0.1 3306, and whatever other IP address your machine is configured to (use ifconfig to find out).

Comments

0

You can test the server setup using the MySQL Workbench or mysql client which will narrow down the problem. It's also sometimes useful to just see if the server's there:

telnet host 3306

It'll tell you the version number of the server and some other binary junk. Enough to know your host is listening.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.