在“读取初始通信数据包"时失去与 MySQL 服务器的连接,系统错误:在 cpanel 中连接到 Mysql 时为 0 [英] Lost connection to MySQL server at 'reading initial communication packet', system error: 0 in connecting to Mysql in cpanel
问题描述
我正在使用 cPanel 服务器,但出现此错误.
I'm using cPanel server and I'm getting this error.
在读取初始通信数据包"时失去与 MySQL 服务器的连接,系统错误:0
Lost connection to MySQL server at 'reading initial communication packet', system error: 0
虽然我读了他的问题 丢失连接在'读取初始通信包'时到MySQL服务器,系统错误:0,我仍然没有得到解决方案.当我运行我的 php 代码时,它返回
Although i read his question Lost connection to MySQL server at 'reading initial communication packet', system error: 0 , I still didn't get the solution. when i run my php code, it returns
连接成功在‘读取初始通信包’时丢失与 MySQL 服务器的连接,系统错误:0"
"Connection successfulLost connection to MySQL server at 'reading initial communication packet', system error: 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);
感谢您的回答.
推荐答案
我能够解决它.这是代码:
I was able to sort it out. here's the code:
$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());
这篇关于在“读取初始通信数据包"时失去与 MySQL 服务器的连接,系统错误:在 cpanel 中连接到 Mysql 时为 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!