1

I'm having a strange problem connecting to a remote MySQL server. Telnet shows the port is open (configured for 3307 instead of 3306), there is no 'bind-address' set in the my.cnf file and all permissions have been granted for both localhost and the IP.

The error returned from the command line is:

ERROR 2003 (HY000): Can't connect to MySQL server on '176.35.197.115' (111 "Connection refused")

And from a simple PHP connection script:

Warning: mysqli_connect(): (HY000/2002): Connection refused in /home/snf/public_html/remote-db-test.php on line 27

Connection refused

The part that is strange is that the same php connection script from a different remote server works perfectly?

The server is an old mac running osx10.8 and MySQL 5.6.26

This is the PHP file (IP, username and password hidden for security):

$link = mysqli_connect("xxx.xxx.xxx.xxx:3307", "xxxxxx", "xxxxxx");
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
$sql = "CREATE DATABASE demo";

if(mysqli_query($link, $sql)){
    echo "Database created successfully";
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
mysqli_close($link);

Anyone have any ideas?

Owen Lewis
  • 11
  • 1
  • 3

1 Answers1

0

Try this, adding the port as a separate argument instead of being part of the host string:

$link = mysqli_connect("xxx.xxx.xxx.xxx", "user", "pass", "dbname", 3307);

PHP documentation link

SpacemanSpiff
  • 249
  • 7
  • 17