Why I get this error 'Communications link failure The last packet sent...' when connecting to MySQL with Java (Netbeans)?

22,335

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.

Share:
22,335
Patryk
Author by

Patryk

Software Engineer C++/Go/shell/python coder Linux enthusiast Github profiles: https://github.com/pmalek https://github.com/pmalekn

Updated on May 27, 2020

Comments

  • Patryk
    Patryk almost 4 years

    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 ?