SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running cron job magento

前端 未结 6 2232
遇见更好的自我
遇见更好的自我 2021-02-07 22:55

I am working on Magento site and I get this error:

SQLSTATE[HY000]: General error: 2006 MySQL server has gone away on running 
cron job magento

6条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 23:27

    DB Connections have a timeout which will cause this error if you try to send a query sometime after opening the connection. The usual scenario is:

    • Open DB connection
    • Fetch some data from DB
    • Do stuff, e.g. send emails (takes time longer than DB connection timeout)
    • Query DB using same connection
    • Error: MySQL server has gone away

    So - what's the solution? You could simply increase the timeout, but that's ugly and could cause problems when traffic to your site increases. The best solution would be to close your DB connection and then re-open it like this:

    • Open DB connection
    • Fetch some data from DB
    • Close DB connection
    • Do stuff, e.g. send emails (takes time longer than DB connection timeout)
    • Open new DB connection
    • Query DB using same connection
    • Close DB connection

    Here's more information: http://dev.mysql.com/doc/refman/5.0/en/gone-away.html

提交回复
热议问题