Peewee MySQL server has gone away

一笑奈何 提交于 2019-12-05 11:53:32

The peewee documentation has talked about this problem, here is the link: Error 2006: MySQL server has gone away

This particular error can occur when MySQL kills an idle database connection. This typically happens with web apps that do not explicitly manage database connections. What happens is your application starts, a connection is opened to handle the first query that executes, and, since that connection is never closed, it remains open, waiting for more queries.

So you have some problems on managing your database connection.


Since I can't reproduce your problem, could you please try this one, close your database this way:

@app.teardown_appcontext
def close_database(error):
    db.close()

And you may get some info from the doc: Step 3: Database Connections

I know this is an old question, but since there's no accepted answer I thought I'd add my two cents.

I was having the same problem when committing largeish amounts of data in Peewee objects (larger than the amount of data MySQL allows in a single commit by default). I fixed it by changing the max_allowed_packet size in my.conf.

To do this, open my.conf, add the following line under [mysqld]:

max_allowed_packet=50M

... or whatever size you need and restart mysqld

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!