mysqli_connect():( HY000 / 2002):连接被拒绝(远程MySQL)

时间:2018-04-06 17:39:17

标签: php mysql mysqli cpanel

我有一个共享的Cpanel Hosting和一个我自己的cpanel托管服务器。我正在尝试从共享的cpanel托管连接到我自己的服务器,以便从我自己的服务器获取数据。 我已将我的共享cpanel托管IP添加到我的远程MySQL部分中的服务器cpanel但我收到上述错误。我还从WHM添加了IP,但没有成功。我已经检查过端口3306也打开了。我不知道什么问题。 我试过下面的连接类型,但总是遇到同样的错误。

$SERVER_NAME = "195.201.XXX.XXX";
$USER_NAME = "MyUserName"; 
$PASSWORD = "MyPass";
$DATABASE = "Mydb";

    $conn = mysqli_connect($SERVER_NAME, $USER_NAME, $PASSWORD, $DATABASE,"3306");

    if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

我也试过下面的代码

 $SERVER_NAME = "195.201.XXX.XXX";
    $USER_NAME = "MyUserName"; 
    $PASSWORD = "MyPass";
    $DATABASE = "Mydb";

        $conn = mysqli_connect($SERVER_NAME, $USER_NAME, $PASSWORD, $DATABASE);

        if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

但是我收到这样的错误

Failed to connect to MySQL: Connection refused 

和像这样的错误日志

mysqli_connect(): (HY000/2002): Connection refused in

让我知道它有什么问题,我该如何解决它。感谢

0 个答案:

没有答案