服务器后台报错:
InterfaceError: 2013: Lost connection to MySQL server during query
具体信息如下:
File "./sr/web/source/manage.py", line 399, in get_tance_users
return MysqlConn().select(sql)
File "./src/lib/mysqlconn.py", line 90, in select
data = cursor.fetchall()
File "/usr/local/lib/python2.7/site-packages/mysql/connector/cursor.py", line 1174, in fetchall
(rows, eof) = self._connection.get_rows()
File "/usr/local/lib/python2.7/site-packages/mysql/connector/connection.py", line 671, in get_rows
rows = self._protocol.read_text_result(self._socket, count)
File "/usr/local/lib/python2.7/site-packages/mysql/connector/protocol.py", line 309, in read_text_result
packet = sock.recv()
File "/usr/local/lib/python2.7/site-packages/mysql/connector/network.py", line 226, in recv_plain
raise errors.InterfaceError(errno=2013)
InterfaceError: 2013: Lost connection to MySQL server during query
单看错误信息,认为是应用在读mysql的时候,使用了一个无效的链接,然后在mysql端kill掉了一些占时间比较长的链接,但是问题依然存在,那么在细看一眼错误:在查询的过程中,对mysql建立的链接丢失了,那么是这什么原因导致的呢?
查询量太大了
后来,将这条sql那到mysql里执行了一下,确实这次查询一共扫描了3亿条数据,返回了1万条数据,就是因为扫描和返回的数据量大导致的,后来程序改成了分页来解决这个问题了,好的产品逻辑设计很重要!