本文介绍了Peewee MySQL服务器不见了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用烧瓶和薄皮纸。有时peewee会引发此错误

I use flask and peewee. Sometimes peewee throws this error

MySQL server has gone away (error(32, 'Broken pipe'))

Peewee数据库连接

Peewee database connection

db = PooledMySQLDatabase(database,**{
            "passwd": password, "user": user,
            "max_connections":None,"stale_timeout":None,
            "threadlocals" : True
        })

@app.before_request
def before_request():
    db.connect()

@app.teardown_request
def teardown_request(exception):
    db.close()

在mysql错误后 MySQL服务器已消失(错误(32,'管道损坏')),选择查询没有问题,但是插入,更新,删除查询不起作用。

After mysql error that "MySQL server has gone away (error(32, 'Broken pipe'))", select queries works without problem, but insert,update,delete queries don't work.

在插入,更新,删除查询后(在mysql中)起作用,但peewee抛出此错误。

On insert,update,delete queries works behind(in mysql) but peewee throw this errors.

(2006, "MySQL server has gone away (error(32, 'Broken pipe'))")


推荐答案

peewee文档讨论了此问题,这里是链接:

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

因此,在管理数据库连接时会遇到一些问题。

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

这篇关于Peewee MySQL服务器不见了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-18 06:27