0

hello there I am new to MySQL Server and I want to connect to MySQL DataBase remotely from my computer other than database placed on! My IP on machine on which I have MySQL server is:

 39.32.58.13

and I am using this code to connect:

    private Connection connect = null;
    private Statement statement = null;
    private PreparedStatement preparedStatement = null;
    private ResultSet resultSet = null;

    private void Connect(){
        try{
        // this will load the MySQL driver, each DB has its own driver
      Class.forName("com.mysql.jdbc.Driver");
      // setup the connection with the DB.
      connect = DriverManager
          .getConnection("jdbc:mysql://39.32.222.77:3306/test","myname", "mypass");
      }
}

But it gives me an error all the time:

    com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.

Is it me doing something wrong because I'm doing it for the first time and need instructions on how to do it ! so please dont mind my mistakes thanks in advance

Java Nerd
  • 958
  • 3
  • 19
  • 51
  • 1
    If the IP of the machine where MySQL server is the first one, why are you using another one in the connection parameter? BTW: Why MySQL and not MariaDB? – Pablo Lozano May 12 '14 at 08:27

3 Answers3

2

You need to grant permission for using mysql fro remote location.

GRANT ALL PRIVILEGES ON *.* TO 'user'@'%.example.com' 
    IDENTIFIED BY PASSWORD 'Password' 
    WITH GRANT OPTION;
FLUSH PRIVILEGES;

where user can be root or any other user

see this for more info on grant

SpringLearner
  • 13,738
  • 20
  • 78
  • 116
1

First,check if the remote mysql database is running. Second,check if your mysql accound has rights to access the database

hope to help you !

miketam
  • 11
  • 2
0

You have to put this as root:

GRANT ALL PRIVILEGES ON *.* TO  'USERNAME'@'IP'  IDENTIFIED  BY  'PASSWORD';

where IP is the IP you want to allow acess and USERNAME is the user you use to connect

If you want to allow access from any IP just put % instead of your IP

and then you only have to put

FLUSH PRIVILEGES

or restart mysql server and that's it.

Here's Answer

Another Tutorial

Community
  • 1
  • 1
user3145373 ツ
  • 7,858
  • 6
  • 43
  • 62