简体   繁体   English

PHP mySQLi:: MySQL 服务器已经消失

[英]PHP mySQLi:: MySQL server has gone away

I'm trying to append a hush database directly from php.我正在尝试直接从 php 附加一个静默数据库。

$mysqli->query(file_get_contents('huge.sql'));

but I'm getting :但我得到:

Warning: mysqli::query(): MySQL server has gone away in 

I was add those 2 line at the beginning of my php code :我在 php 代码的开头添加了这两行:

ini_set('mysql.connect_timeout',3000);
ini_set('default_socket_timeout',3000);

Not very helpful...不是很有帮助...

Unless you're getting an actual error and not a Warning, this doesn't necessarily mean you're doing something wrong.除非您收到实际错误而不是警告,否则这并不一定意味着您做错了什么。

With PDO for example, this warning can be issued when pooled connections are in use, such as when PHP is running as an Apache Module.以 PDO 为例,在使用池连接时会发出此警告,例如当 PHP 作为 Apache 模块运行时。 There is a similar post here: How to fix the "server has gone away" warning when mysqli reconnects a persistent connection?这里有一个类似的帖子: How to fix the "server has gone away" warning when mysqli reconnects a persistent connection?

If what you're getting is simply a warning, and the query runs fine anyway, then you can either choose to request a persistent mysql connection, or ignore and suppress the warning.如果您得到的只是一个警告,并且查询运行正常,那么您可以选择请求持久的 mysql 连接,或者忽略并抑制警告。

If you're getting an error and your connection is getting terminated, then you should see https://dev.mysql.com/doc/refman/8.0/en/gone-away.html for most common causes of this issue.如果您收到错误并且您的连接被终止,那么您应该查看https://dev.mysql.com/doc/refman/8.0/en/gone-away.html以了解此问题的最常见原因。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM