0

Hello I have a centos server and I have succeeded setting remote connection from software like Navicat on windows, remoDB on android. But the problem is, I can't connect to the server from my other hosting.

here is my code sample

<?php
$servername = "******";
$username = "***";
$password = '*****';

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

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

and the error i got is this

Connection failed: Can't connect to MySQL server on '*****' (111 "Connection refused")

2 Answers2

0

What do you mean about "other hosting"? I guess it's not localhost. Maybe you have used "over ssh" connection when you used Navicat, so that why it was not denied.

111 error reflects "connection refused", it means that your mysqld only listens to the localhost. Solution: you need to edit (or comment) bind-address value in the mysqld section of your my.cnf file (check “how to locate my.cnf”?)

  • comment this line bind-address = 127.0.0.1 to #bind-address = 127.0.0.1
  • then restart mysql
4givN
  • 2,936
  • 2
  • 22
  • 51
  • Hi, thank you. I am not using over ssh connection in navicat or remodb (android app). I've been searching my.cnf file on my server, I only found one in /etc/my.cnf and there are only few lines, and there is no bind-address value. – Riddict Dev Jul 14 '17 at 03:58
0

Another guesses : Try to specify db_name, port, socket:

  • make sure you use the right port : mysqladmin -u {user} -p{pwd} variables | grep port
  • make sure you use the right socket : mysqladmin -u {user} -p{pwd} variables | grep sock

  • Then proceed like this: $conn = new mysqli('localhost', 'my_user', 'my_password', 'my_db’, ‘xxxx’, ‘{path to my socket}/mysql.sock’);

4givN
  • 2,936
  • 2
  • 22
  • 51
  • Not working either bro, I don't know what is the problem here. I telnet to the server with port 3306, the connection was established. – Riddict Dev Jul 15 '17 at 10:06