3

I am trying to use MySQL database (that is installed on virtual machine (Debian) on my pc and has IP address 192.168.1.5 ) from Java with use of NetBeans.

I have configured the connection as follows :

Driver Name MySQL(Connector/J Driver) Host 192.168.1.5 Database test Username root Password * JDBC URL jdbc:mysql://192.168.1.5:3306/test 

and then I get the following error :

cannot establish a connection to jdbc:mysql://192.168.1.5:3306/test using  com.mysql.jdbc.Driver (Communications link failure  The last packet sent successfully  to the server was 0 milliseconds ago. The driver has not received any packets  from the server.) 

My mysql.user table looks like this ( I know % root is not very secure but this is just to simplify things for the moment):

+------------+------------------+ | host | user | +------------+------------------+ | % | root | | 127.0.0.1 | root | | ::1 | root | | debVirtual | | | localhost | | | localhost | debian-sys-maint | | localhost | phpmyadmin | | localhost | root | +------------+------------------+ 

What can I do to allow this connection ?

0

4 Answers 4

5

The problem was with mysql configuration file on the server /etc/mysql/my.cnf

the line : bind-address should point to your server's IP like in this example

bind-address = 192.168.1.5

and not

bind-address = 127.0.0.1

to allow remote access.

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

1 Comment

I did all these steps but I still had the problem, finally, I found it was firewalld!!
0

Can you post your entire code?

That error comes when the database youre trying to reach does not exist. Check your network setting in your VM software. What type of VM software are you using (VirtualBox, VM ware...)

Comments

0

This is either the wrong folder, or I have a different version. I am running Lubuntu and the file is not my.cnf (because that file does not have a bind-address). the bind-address is situated in a file in /etc/mysql/mysql.conf.d/ whose name is: mysqld.cnf. You cannot modify it by the file manager so you have to go through the following command lines:

sudo su ***enter password*** cd /etc/mysql/mysql.conf.d nano mysqld.cnf 

then go to bind-address 127.0.0.1 and change it to the IPv4 that you can find in

ifconfig 

I hope I helped.

Comments

-1

Perfect solution:

  1. Start wamp server before netbeans
  2. Then open netbeans

It worked for me. When I close the wamp server, it shows me this error:

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.