错误2006:"MySQL服务器已消失";使用Python,Bottle Microframework和Apache [英] Error 2006: "MySQL server has gone away" using Python, Bottle Microframework and Apache

查看:87
本文介绍了错误2006:"MySQL服务器已消失";使用Python,Bottle Microframework和Apache的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下命令访问我的Web应用程序后:
-Python 2.7
-Bottle micro framework v.0.10.6
-Apache 2.2.22
-mod_wsgi
-在Ubuntu Server 12.04 64bit上;几个小时后,我收到此错误:

After accessing my web app using:
- Python 2.7
- the Bottle micro framework v. 0.10.6
- Apache 2.2.22
- mod_wsgi
- on Ubuntu Server 12.04 64bit; I'm receiving this error after several hours:

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

我正在使用MySQL-Python中包含的本机MySQL.当我不访问服务器时,通常会发生这种情况.我尝试使用以下方法关闭所有连接:

I'm using MySQL - the native one included in Python. It usually happens when I don't access the server. I've tried closing all the connections, which I do, using this:

cursor.close()
db.close()

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

where db is the standard MySQLdb.Connection() call.

my.cnf文件如下所示:

The my.cnf file looks something like this:

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.

It is the default configuration file except max_allowed_packet is 128M instead of 16M.

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

The queries to the database are quite simple, at most they retrieve approximately 100 records.

有人可以帮我解决这个问题吗?我确实有一个想法是使用try/except,但是我不确定那是否真的有用.

Can anyone help me fix this? One idea I did have was use try/except but I'm not sure if that would actually work.

预先感谢

杰米

更新:try/except呼叫无效.

Update: try/except calls didn't work.

推荐答案

这是MySQL错误,而不是Python错误.

This is MySQL error, not Python's.

可能的原因和可能的解决方案的列表在这里: MySQL 5.5参考手册:C .5.2.9. MySQL服务器不见了.

The list of possible causes and possible solutions is here: MySQL 5.5 Reference Manual: C.5.2.9. MySQL server has gone away.

可能的原因包括:

  • 您尝试在关闭与服务器的连接后运行查询.这表明应纠正应用程序中的逻辑错误.
  • 在其他主机上运行的客户端应用程序没有从该主机连接到MySQL服务器所需的特权.
  • 您在服务器端遇到了超时,并且客户端中的自动重新连接被禁用(MYSQL结构中的重新连接标志等于0).
  • 如果向服务器发送不正确或太大的查询,也会出现这些错误.如果mysqld收到的数据包太大或顺序混乱,则认为客户端出了点问题,并关闭了连接.如果需要大型查询(例如,如果使用大型BLOB列),则可以通过设置服务器的第C.5.2.10节,数据包太大" .
  • 如果客户端的版本低于4.0.8并且服务器的版本为4.0.8及更高版本,或者如果发送的数据包为16MB或更大,则连接也会丢失.
  • 依此类推...
  • 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...

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

In other words, there are plenty of possible causes. Go through that list and check every possible cause.

这篇关于错误2006:"MySQL服务器已消失";使用Python,Bottle Microframework和Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆