远程MySQL连接被拒绝

时间:2018-04-05 11:58:15

标签: mysql remote-access

我在连接到远程MySQL服务器时遇到了一个奇怪的问题。 Telnet显示端口已打开(配置为3307而不是3306),没有'绑定地址'在my.cnf文件中设置,并且已为localhost和IP授予所有权限。

命令行返回的错误是:

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

来自simple PHP connection script

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

拒绝连接

奇怪的部分是same php connection script from a different remote server完美无缺?

服务器是运行osx10.8和MySQL 5.6.26

的旧mac

这是PHP文件(为安全而隐藏的IP,用户名和密码):

$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);

有人有什么想法吗?

1 个答案:

答案 0 :(得分:0)

尝试此操作,将端口作为单独的参数添加,而不是作为主机字符串的一部分:

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

PHP documentation link