简体   繁体   English

从PHP连接到我的localhost MySQL实例的间歇性错误:mysqli_connect():HY000 / 2013

[英]Intermittent error connecting to my localhost MySQL instance from PHP: mysqli_connect(): HY000/2013

I have a LAMP website (PHP/MySQL), and I rely heavily on my MySQL database. 我有一个LAMP网站(PHP / MySQL),我非常依赖我的MySQL数据库。

Recently, the following error started occurring intermittently: 最近,间歇性地发生以下错误:

[30-Oct-2011 16:11:49] PHP Warning:  mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'sending authentication information', system error: 32 in /home/path/to/my/code.php on line 1029

This is line 1029, the specific line that occasionally gives the above error: 这是第1029行,偶尔会给出上述错误的具体行:

$db = mysqli_connect($cfg['db_location'], $cfg['db_reader_username'], $cfg['db_reader_password']);

where $cfg['db_location'] is "localhost" , and the username and password are correct. 其中$cfg['db_location']"localhost" ,用户名和密码是正确的。

It appears as though something is causing my PHP script to intermittently lose connection to the MySQL server, which is puzzling to me because all of my MySQL connections are made to localhost. 似乎某些东西导致我的PHP脚本间歇性地失去与MySQL服务器的连接,这让我感到困惑,因为我的所有 MySQL连接都是针对localhost的。 That is, the PHP script and the MySQL server are both running on the same box, and I connect to MySQL via localhost. 也就是说,PHP脚本和MySQL服务器都在同一个盒子上运行,我通过localhost连接到MySQL。

Additionally, this is puzzling because my PHP script is able to successfully connect to the MySQL server for perhaps 90% of pages. 此外,这是令人费解的,因为我的PHP脚本能够成功连接到MySQL服务器,可能有90%的页面。

As best I can tell, my server has plenty of available RAM and CPU: 我可以说,我的服务器有足够的RAM和CPU:

top - 16:38:23 up 173 days, 19:19,  2 users,  load average: 0.57, 0.78, 0.84
Tasks: 142 total,   4 running, 137 sleeping,   0 stopped,   1 zombie
Cpu(s): 18.7%us, 27.5%sy,  0.7%ni, 52.6%id,  0.2%wa,  0.1%hi,  0.2%si,  0.0%st
Mem:   2976260k total,  1861368k used,  1114892k free,   532628k buffers
Swap:  2048248k total,      116k used,  2048132k free,  1035804k cached

And plenty of available disk space. 并且有足够的可用磁盘空间。 When I run df -h , all of my filesystems are at most 25% in use. 当我运行df -h ,我的所有文件系统最多使用25%。

So I don't know what would be causing the sporadic errors that I'm seeing in my PHP error logs. 所以我不知道什么会导致我在PHP错误日志中看到的零星错误。

Any ideas what might be causing my PHP script to intermittently lose connection to my MySQL server on localhost? 有什么想法可能导致我的PHP脚本间歇性地失去与localhost上的MySQL服务器的连接?

I upgraded to MySQL 5.1, and this is now what get when I run mysql -V : 我升级到MySQL 5.1,这是我运行mysql -V时得到的:

mysql  Ver 14.14 Distrib 5.1.56, for pc-linux-gnu (i686) using readline 5.1

The same errors are still happening, though: 但是仍然会发生同样的错误:

[30-Oct-2011 20:26:18] PHP Warning:  mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'sending authentication information', system error: 32 in /home/path/to/my/code.php on line 1029

As before, the errors continue to be intermittent. 和以前一样,错误仍然是间歇性的。

After I upgraded to MySQL 5.1, I've been looking carefully at my PHP errors logs. 升级到MySQL 5.1后,我一直在仔细查看我的PHP错误日志。 I've noticed a few other errors similar to the first one. 我注意到其他一些与第一个类似的错误。 For example, here's one such error: 例如,这是一个这样的错误:

[30-Oct-2011 22:42:29] PHP Warning:  mysqli_connect() [<a href='function.mysqli-connect'>function.mysqli-connect</a>]: (HY000/2013): Lost connection to MySQL server at 'reading authorization packet', system error: 104 in /home/path/to/my/code.php on line 1029

And here's another error I've seen in my logs: 这是我在日志中看到的另一个错误:

PHP Warning:  mysqli::mysqli() [<a href='mysqli.mysqli'>mysqli.mysqli</a>]: (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/path/to/different/code.php on line 7

In all cases, the problem fundamentally seems to be a failure to connect to MySQL. 在所有情况下,问题从根本上似乎是连接到MySQL失败。 Any ideas what might be causing this or how I could debug it? 什么可能导致这个或我如何调试它的想法?

Perhaps this bug report will help - It seems that a fix may be to set a higher timeout for the global connect_timeout . 也许这个错误报告会有所帮助 - 似乎修复可能是为全局connect_timeout设置更高的超时。 It was set to a higher value in later versions of MySQL 5.1 (10 seconds) as opposed to 5 seconds for earlier versions. 它在MySQL 5.1的后续版本中设置为更高的值(10秒),而早期版本则为5秒。

http://bugs.mysql.com/bug.php?id=28359 http://bugs.mysql.com/bug.php?id=28359

暂无
暂无

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

相关问题 mysqli_connect() mysqli_connect(): (HY000/2002): 从其他 php 文件调用时没有此类文件或目录错误 - mysqli_connect() mysqli_connect(): (HY000/2002): No such file or directory error when calling from other php file PHP和MySQL错误:mysqli_connect()[function.mysqli-connect]:(HY000 / 2005):未知的MySQL服务器主机 - PHP & MySQL Error: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host 连接到外部数据库时出错 - mysqli_connect(): (HY000/2002): Connection timed out - Error when connecting to external db - mysqli_connect(): (HY000/2002): Connection timed out PHP和MySQL警告:mysqli_connect()[function.mysqli-connect]:(HY000 / 2005):未知的MySQL服务器主机 - PHP & MySQL Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host localhost: socket: mysqli_connect(): (HY000/2002): 没有那个文件或目录 - localhost: socket: mysqli_connect(): (HY000/2002): No such file or directory mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (使用密码: NO) - mysqli_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) 警告:mysqli_connect(): (HY000/1045): 用户 &#39;usr&#39;@&#39;localhost&#39; 访问被拒绝(使用密码:YES) - Warning: mysqli_connect(): (HY000/1045): Access denied for user 'usr'@'localhost' (using password: YES) 警告:mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) - Warning: mysqli_connect(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) 使用mysqli在localhost或127.0.0.1上连接时出现HY000 / 2003错误 - HY000/2003 error using mysqli to connect on localhost or 127.0.0.1 mysqli_connect():(HY000 / 2002):无法通过套接字连接到本地MySQL服务器 - mysqli_connect(): (HY000/2002): Can't connect to local MySQL server through socket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM