简体   繁体   English

MySQL使用Laravel 5.4连接错误

[英]MySQL Too many connections error using Laravel 5.4

I have a Laravel 5.4 web app running on a shared hosting ( a2hosting ) and once every now and then I get a SQLSTATE[08004][1040] Too many connections error. 我有一个在共享主机( a2hosting )上运行的Laravel 5.4 Web应用,一次又一次出现SQLSTATE[08004][1040] Too many connections错误。 Some times it takes a few minutes to start working again, some times it has taken hours. 有时需要几分钟才能重新开始工作,有时则需要数小时。

I have tried several things to diagnose the problem and to try to fix it but nothing has worked so far. 我已经尝试了几种方法来诊断问题并尝试解决问题,但到目前为止没有任何效果。

max_connections is set to 500 and wait_timeout is set to 8 hours. max_connections设置为500, wait_timeout设置为8小时。

If I log in into the mysql cli while the error is still poping out and list the active processes it show's no more than 10 ~ 15 processes. 如果在错误仍然弹出的情况下登录mysql cli并列出活动进程,则该进程显示的进程数不超过10〜15个。

Also the system is only used by some 30 people so I have no idea why the max number of connections could be reached (maybe php is not closing some connections for some reason?). 另外该系统仅由大约30个人使用,所以我不知道为什么可以达到最大连接数(也许php由于某些原因没有关闭某些连接?)。

Has anyone encountered an error like this? 有没有人遇到这样的错误? and if so what have you done to fix it? 如果是这样,您做了什么修复? Also any ideas of what could be causing the error and how to prevent/fix it? 还有关于什么可能导致该错误以及如何防止/修复该错误的任何想法?

I can provide more info on my laravel app, db, and server if it could help diagnose the problem. 如果可以帮助诊断问题,我可以在laravel应用程序,数据库和服务器上提供更多信息。

Possible causes: 可能的原因:

  • "Connection pooling" is turned on (somewhere), and set too high. “连接池”已打开(在某个位置),并且设置得太高。
  • The Web server has too many 'children'; Web服务器的“子级”过多; lower its limit. 降低其极限。
  • There may be 'slow' queries that need optimizing. 可能有“慢”查询需要优化。
  • The connections fail to 'disconnect' when finished. 连接完成后无法“断开连接”。
  • Decrease, not increase, wait_timeout . 减少而不是增加wait_timeout
  • There are multiple wait_timeout settings; 有多个wait_timeout设置; you changed the wrong one. 您改错了。
  • Increasing the number of simultaneous connections can make the overall performance worse. 同时连接数量的增加可能会使整体性能变差。

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

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