1

I am trying to access remote MySQL server by its IP using PHP.

Here is my code:

$servername = "100.XXX.XXX.XXX:3306"; // MySQL IP
$username = "root";
$password = "Password012";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} else {
    echo "success";
}

This is working fine on my local machine but not on live.

I am getting this error:

Warning: mysqli::mysqli(): (HY000/2002): Connection refused in [...]

Any suggestions?

lolbas
  • 794
  • 1
  • 9
  • 34
Hitu Bansal
  • 2,917
  • 10
  • 52
  • 87

1 Answers1

0

You need to allow remote connection on your mysql server.

To do that, execute the following command in your mysql server. Please change the databasename and username from the following command, before execute the command

GRANT ALL PRIVILEGES ON databasename . * TO 'username'@'%';