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

前端 未结 6 2213
遇见更好的自我
遇见更好的自我 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:01

    I've encountered this error before. For my case it was due the database size is too large, more than 18gb for 5 years data.

    The only solution that is working for me was to dump all those data and create a new database.

    0 讨论(0)
  • 2021-02-07 23:08

    If you have any actions which do not operate with Magento DB for more than 20 seconds (I met shared hosting with such wait_timeout=20), you have to close DB connection. Magento will create new connection on next call to DB.

        Mage::getSingleton('core/resource')->getConnection('read')->closeConnection();
    
    0 讨论(0)
  • 2021-02-07 23:09

    You may also look into index table size when using shared hosting. It may take much space because of that also you may get "mysql server gone away".

    0 讨论(0)
  • 2021-02-07 23:11

    I don't have any timeout issues.

    I moved a fclose(STDERR) line from my main file to a included file and this started happening.

    SQLSTATE[HY000]: General error: 2006 MySQL server has gone away

    I moved the line back to its original place and problem went away.

    Basically, closing STDERR from an included file seems to have some crazy repercussions.

    0 讨论(0)
  • 2021-02-07 23:14

    If you got this error with the phpsh interpreter. I am able to reproduce this error with phpsh and a new shell to doctrine manager.

    SQLSTATE[HY000]: General error: 2006 MySQL server has gone away 
    

    With this command in the phpsh interpreter:

    php> $result = $conn->query('select psetid from psetproblems')->fetchAll();
    

    Explanation:

    This error is the MySQL timeout error. Either you waited too long in between creating your connection and then actually using it, or you made an error with one of your commands and you ruined the connection. The simplest solution is to stop, restart everything and don't run the command that throws an error, and do it quickly. It should work.

    Solution

    Restart your interpreter. Don't submit errors and be faster in issuing your commands through your interpreter.

    You could increase the timeout length of your MySQL connection for PHP. Then you can wait longer between creating a connection, then using it.

    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题