简体   繁体   English

mysqli_connect(): (HY000/2006): MySQL 服务器已经消失

[英]mysqli_connect(): (HY000/2006): MySQL server has gone away

I get this error:我收到此错误:

Warning: mysqli_connect(): MySQL server has gone away in C:\Apache24\htdocs\soccer.php on line 5

Warning: mysqli_connect(): Error while reading greeting packet. PID=19176 in C:\Apache24\htdocs\soccer.php on line 5

Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\Apache24\htdocs\soccer.php on line 5

Fatal error: Maximum execution time of 30 seconds exceeded in C:\Apache24\htdocs\soccer.php on line 5

when trying to run a php file on localhost.尝试在本地主机上运行 php 文件时。 php7.2 MySQL 8 i have tried alot of suggested soltutions on for hours but no success. php7.2 MySQL 8 我已经尝试了很多小时的建议解决方案,但没有成功。 here is the PHP code which i am just using for other purpose and dont understand all of it but just because i want to connect a database to may Application这是我仅用于其他目的的 PHP 代码,并不了解所有内容,但只是因为我想将数据库连接到可能的应用程序

    <?php 
$con = mysqli_connect("localhost:81","root","root","testdb") or die ("could not connect to mysql");;

if(mysqli_connect_error($con))
{

    echo "Failed to connect";

}

$query = mysqli_query($con,"SELECT * FROM testtb");

if($query){
    while($row=mysqli_fetch_assoc($query))
    {
        $flag[] = $row;
    }
    print(json_encode($flag));

    mysql_free_result($query);
}

 mysqli_close($con);
?>

Mysql Server use 3306 port as a default. Mysql Server 默认使用 3306 端口。 You are trying to connect with Mysql 81 port and Mysql refused to connect with that port.您正在尝试连接 Mysql 81 端口,而 Mysql 拒绝连接该端口。 So change所以改变

$con = mysqli_connect("localhost:81","root","root","testdb") or die ("could not connect to mysql");;

to

$con = mysqli_connect("localhost:3306","root","root","testdb") or die ("could not connect to mysql");;

By the way yo don't need to write port.顺便说一句,你不需要写端口。 3306 is default. 3306 是默认值。

$con = mysqli_connect("localhost","root","root","testdb") or die ("could not connect to mysql");;

好吧,出于某种原因,我使用了127.0.0.1而不是localhost并且工作了无论如何感谢您的帮助。

if you are using xampp then check the port number of mysql server and change this ---->>如果您使用的是xampp,请检查 mysql 服务器的端口号并更改此 ---->>

$con = mysqli_connect("localhost:81","root","root","testdb")

to ---->>到---->>

$con = mysqli_connect("127.0.0.1:3306","root","root","testdb")

In the place of 3306 you can put your mysql server port number.3306的位置,您可以输入您的 mysql 服务器端口号。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:mysqli_connect(): (HY000/2006): MySQL 服务器已经消失 - Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away mysqli_real_connect():(HY000 / 2006):MySQL服务器已消失 - mysqli_real_connect(): (HY000/2006): MySQL server has gone away HY000 2006 MySQL 服务器不见了 - HY000 2006 MySQL server has gone away mysqli_real_connect(): (HY000/2006): MySQL 服务器已经消失 - max_allowed_packet 不好 - mysqli_real_connect(): (HY000/2006): MySQL server has gone away - max_allowed_packet no good 尝试连接时出现“ SQLSTATE [HY000] [2006] MySQL服务器已消失” - I am getting “SQLSTATE[HY000] [2006] MySQL server has gone away” when attempting to connect 将 Laravel 连接到 XAMPP MySQL (MariaDB) 数据库 SQLSTATE[HY000] [2006] MySQL 服务器已经消失 - Connecting Laravel to XAMPP MySQL (MariaDB) database SQLSTATE[HY000] [2006] MySQL server has gone away SQLSTATE [HY000]:常规错误:2006 MySQL服务器已消失,无法创建临时表 - SQLSTATE[HY000]: General error: 2006 MySQL server has gone away creating temporary table Symfony 3 : SQLSTATE[HY000] [2006] MySQL 服务器在更新模式期间消失了 - Symfony 3 : SQLSTATE[HY000] [2006] MySQL server has gone away during update schema PDO例外:SQLSTATE [HY000] [2006] MySQL服务器已经消失了xampp - PDO Exception:SQLSTATE[HY000] [2006] MySQL server has gone away with xampp Doctrine\\DBAL\\Driver\\PDOException SQLSTATE[HY000] [2006] MySQL 服务器已经消失 - Doctrine\DBAL\Driver\PDOException SQLSTATE[HY000] [2006] MySQL server has gone away
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM