Peewee MySQL服务器不见了

编程入门 行业动态 更新时间:2024-10-25 16:20:04
本文介绍了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文档讨论了此问题,这里是链接:错误2006:MySQL服务器已消失

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

当MySQL终止空闲的数据库连接时,可能会发生此特定错误。对于未明确管理数据库连接的Web应用程序,通常会发生这种情况。发生的情况是您的应用程序启动,打开了连接以处理执行的第一个查询,并且由于该连接从未关闭,因此它将保持打开状态,等待更多查询。

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()

您可能会得到一些文档中的信息:第3步:数据库连接

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

更多推荐

Peewee MySQL服务器不见了

本文发布于:2023-11-16 18:52:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606910.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不见了   服务器   Peewee   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!