Python and Django OperationalError (2006, 'MySQL server has gone away')

后端 未结 12 1741
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 15:25

Original: I have recently started getting MySQL OperationalErrors from some of my old code and cannot seem to trace back the problem. Since it was working before, I thought

12条回答
  •  情书的邮戳
    2020-12-14 15:59

    In my opinion, the must common issue regarding such warning, is the fact that your application has reached the wait_timeout value of MySQL.

    I had the same problem with a PythonFLASK app which I developed and I solved very easy.

    P.S: I was using MySQL 5.7.14

    $ grep timeout /etc/mysql/mysql.conf.d/mysqld.cnf 
    # https://support.rackspace.com/how-to/how-to-change-the-mysql-timeout-on-a-server/
    # wait = timeout for application session (tdm)
    # inteactive = timeout for keyboard session (terminal)
    # 7 days = 604800s / 4 hours = 14400s 
    wait_timeout = 604800
    interactive_timeout = 14400
    

    One important observation: if you search for the variables via MySQL batch mode, the values will appear as it is. But If you perform "SHOW VARIABLES LIKE 'wait%';" or "SHOW VARIABLES LIKE 'interactive%';", the value configured for 'interactive_timeout', will appear to both variables, and I don't know why, but the fact is, that the values configured for each variable at '/etc/mysql/mysql.conf.d/mysqld.cnf', will be respected by MySQL process.

    Regards!

提交回复
热议问题