我在连接到远程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);
有人有什么想法吗?
答案 0 :(得分:0)
尝试此操作,将端口作为单独的参数添加,而不是作为主机字符串的一部分:
$link = mysqli_connect("xxx.xxx.xxx.xxx", "user", "pass", "dbname", 3307);