简体   繁体   English

PHP无法在RDS上连接到MySQL

[英]PHP cannot connect to MySQL on RDS

Recently few days I run into a weird problem of php not able to connect to mysql on RDS, while manual connections are fine. 最近几天,我遇到了一个奇怪的问题,即php无法在RDS上连接到mysql,而手动连接很好。

So I have several php scripts sitting on our server which is hosted on EC2, and these scripts are called by the clients to communicate with a mysql server sitting on RDS. 因此,我在托管在EC2上的服务器上有几个php脚本,客户端调用了这些脚本来与RDS上的mysql服务器通信。 The scripts are setup so that if any connection error occurs, they would send email notification to me. 设置了脚本,以便如果发生任何连接错误,它们将向我发送电子邮件通知。

So for the recent few days I'm receiving thousands of error emails from my scripts, at the first few days the errors were simple saying the server host is not recognized, but I am sure the address is correct. 因此,最近几天我收到了来自脚本的成千上万条错误电子邮件,在开始的几天里,错误很简单,说服务器主机无法识别,但是我确定地址是正确的。 And now the errors are almost all saying "Host XXX is blocked because of many connection errors, unblock with mysqladmin flush-hosts..." If I flush the hosts, the errors come back to me after a while. 现在,错误几乎都说“由于许多连接错误而阻止了主机XXX,请使用mysqladmin flush-hosts取消阻止...”如果我刷新了主机,则错误会在一段时间后再次出现。

What confuses me the most is that, I cannot reproduce the problem! 最让我困惑的是,我无法重现问题! I tried connecting to the RDS server from my EC2 server through command line and through test php scripts... They all work! 我尝试通过命令行和测试php脚本从EC2服务器连接到RDS服务器...它们都可以工作! If I manually invoke the scripts sending me error emails, they work too! 如果我手动调用向我发送错误电子邮件的脚本,它们也会起作用! Looking at the RDS monitor, all stat looks normal, CPU is bouncing around 50%, and plenty of hard drive space. 查看RDS监视器,所有统​​计信息看起来都很正常,CPU跳动了50%左右,并且有足够的硬盘空间。

So I'm totally confused right now... Can anyone provide me some insight about how to solve this problem? 所以我现在很困惑...谁能为我提供一些有关如何解决此问题的见解? I don't even know where to look at now... 我什至不知道现在看哪里...

you need to check your connection to the mysql server and check for errors. 您需要检查与mysql服务器的连接并检查错误。 Until then you can cron a "flush hosts" to temporary fix the issue. 在此之前,您可以设置“刷新主机”以暂时解决此问题。 Be aware that this should be used only as a temporary fix. 请注意,这仅应用作临时修补程序。

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

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