gpt4 book ai didi

python - 错误 2006 : "MySQL server has gone away" using Python, Bottle Microframework 和 Apache

转载 作者:可可西里 更新时间:2023-11-01 06:54:00 25 4
gpt4 key购买 nike

使用以下方法访问我的网络应用程序后:
- Python 2.7
- Bottle 微框架 v. 0.10.6
- Apache 2.2.22
- mod_wsgi
- 在 Ubuntu 服务器 12.04 64 位上;几个小时后我收到此错误:

OperationalError: (2006, 'MySQL server has gone away')

我正在使用 MySQL - Python 中包含的 native 版本。它通常发生在我不访问服务器时。我已经尝试使用以下方法关闭所有连接:

cursor.close()
db.close()

其中 db 是标准的 MySQLdb.Connection() 调用。

my.cnf 文件看起来像这样:

key_buffer      = 16M
max_allowed_packet = 128M
thread_stack = 192K
thread_cache_size = 8
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
#table_cache = 64
#thread_concurrency = 10

这是默认的配置文件,除了 max_allowed_pa​​cket 是 128M 而不是 16M。

对数据库的查询非常简单,最多检索大约 100 条记录。

谁能帮我解决这个问题?我确实有一个想法是使用 try/except,但我不确定这是否真的有效。

提前致谢

杰米

更新:try/except 调用无效。

最佳答案

这是 MySQL 的错误,不是 Python 的。

此处列出了可能的原因和可能的解决方案:MySQL 5.5 Reference Manual: C.5.2.9. MySQL server has gone away .

可能的原因包括:

  • You tried to run a query after closing the connection to the server. This indicates a logic error in the application that should be corrected.
  • A client application running on a different host does not have the necessary privileges to connect to the MySQL server from that host.
  • You have encountered a timeout on the server side and the automatic reconnection in the client is disabled (the reconnect flag in the MYSQL structure is equal to 0).
  • You can also get these errors if you send a query to the server that is incorrect or too large. If mysqld receives a packet that is too large or out of order, it assumes that something has gone wrong with the client and closes the connection. If you need big queries (for example, if you are working with big BLOB columns), you can increase the query limit by setting the server's max_allowed_packet variable, which has a default value of 1MB. You may also need to increase the maximum packet size on the client end. More information on setting the packet size is given in Section C.5.2.10, “Packet too large”.
  • You also get a lost connection if you are sending a packet 16MB or larger if your client is older than 4.0.8 and your server is 4.0.8 and above, or the other way around.
  • and so on...

换句话说,有很多可能的原因。浏览该列表并检查所有可能的原因。

关于python - 错误 2006 : "MySQL server has gone away" using Python, Bottle Microframework 和 Apache,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12444272/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com