Skip to main content

"Lost connection to MySQL server during query" with Python App

Comments

5 comments

  • cPanelMichael
    Hello, Do you have root access to the affected system in order to view the MySQL error log when encountering the timeout? If not, have you contacted your hosting provider to see if they can take a closer look to see if it's related to the MySQL configuration values in the /etc/my.cnf file on the system? Thank you.
    0
  • TragedyStruck
    This has been resolved. For people who might be in trouble, my solution was this: It was a timeout issue. Specifically my hosting provider had set a very low WAIT_TIMEOUT for their MySQL server. The MySQL-default is 28800 (8 hours), while they had set it to 100 (1 minute 40 seconds). Since I was using SQLAlchemy for ORM it had to reflect that low value in order to not fail when trying to use a timed out connection. In my SQLAlchemy config I set this value:
    SQLALCHEMY_POOL_RECYCLE=90
    To figure out the timeout value my hosting provider was using I ran this query:
    SHOW SESSION VARIABLES LIKE 'wait_timeout';
    Resulting in this:
    +---------------+-------+ | Variable_name | Value | +---------------+-------+ | wait_timeout | 100 | +---------------+-------+
    0
  • cPanelMichael
    Hello, I'm happy to see the issue is now solved. Thank you for updating us with the outcome.
    0
  • venkatesh123
    Hello, SHOW SESSION VARIABLES LIKE 'wait_timeout'; = 28800 SQLALCHEMY_POOL_RECYCLE = 28700 but still, I am getting the same error,I am using the flask sqlalchemy running a cronjob which will trigger every hour 10th minute (* 10) at every day 10' o clock I am getting (pymysql.err.OperationalError) (2013, 'Lost connection to MySQL server during query') can anyone please help?
    0
  • MichellePaige
    This is very helpful
    0

Please sign in to leave a comment.