在“读取初始通信数据包”时失去与MySQL服务器的连接,系统错误:在cpanel中连接到Mysql时为0


Lost connection to MySQL server at 'reading initial communication packet', system error: 0 in connecting to Mysql in cpanel

我正在使用cPanel服务器,但收到此错误。

在"读取初始通信数据包"时失去与MySQL服务器的连接,系统错误:0

虽然我读了他的问题"读取初始通信数据包"时失去与MySQL服务器的连接,系统错误:0,但我仍然没有得到解决方案。 当我运行我的 PHP 代码时,它返回

"连接成功在'读取初始通信数据包'时失去与 MySQL 服务器的连接,系统错误:0"

代码如下:

$con = mysql_connect('mysite.com:2082', 'me@mysite.com', 'passwordhere', 'dbname');
if (mysqli_connect_errno($con))
  {
   echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
else
{
    echo "Connection successful";
}
if ($selected = mysql_select_db("dbname",$con) or die(mysql_error())){
    echo "Your database name is dbname";
}

mysqli_close($con);

感谢您的回答。

我能够解决它。 代码如下:

    $con = mysql_connect('localhost', 'serverusername', 'serverpassword');
    if (mysqli_connect_errno($con))
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }
    $selected = mysql_select_db("db_name",$con) or die(mysql_error());