我正在使用python 2.7和pymysql模块从MySQL数据库中提取数据。当我执行以下代码来选择数据时,我不断收到错误(在底部)(执行查询后出错):
conn = pms.connect(Host,User,Pwd,DB)
with conn:
cur = conn.cursor() # Create cursor to interact with MySQL
cur.execute(query)
其中查询为:
SELECT Time,var1,var2,var3 FROM tableName WHERE Time BETWEEN '2017-02-08 00:00:00' AND '2017-02-15 00:00:00'
我很乐意发布更多的代码,但它非常大,所以最好先尝试缩小可能导致问题的原因。
当我尝试提取大量(数据)数据(数千万行)时,才会出现此问题。在这种情况下,我从100 Hz采样率数据中提取4个变量,包括时间。数据库表中的主键是Time。
FYI :我能够在相同的时间段内使用COUNT命令对MySQL执行类似的请求而没有错误:
SELECT COUNT(Time) FROM tableName WHERE Time BETWEEN '2017-02-08 00:00:00' AND '2017-02-15 00:00:00'
理论1:从Google问题的结果来看,我怀疑它可能是因使用GUI而引起的与线程相关的问题。但我并没有有意识地在这个程序中创建任何线程。话虽如此,我正在学习,可能对此很天真。
理论2:另一个怀疑是,当文件大小超过阈值限制时,从MySQL读取数据的方式会发生变化。也许创建了新的线程/连接来处理请求,并且由于与pymysql的Threadsafety值为1相关的限制而发生错误(根据谷歌搜索问题)。
问题: 15分钟后连接是否会超时?
关键点:
错误信息:以下是您的信息的完整错误。感谢您抽出宝贵时间阅读本文。
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydevd.py", line 1578, in <module>
globals = debugger.run(setup['file'], None, None, is_module)
File "C:\Program Files (x86)\JetBrains\PyCharm Community Edition 2017.1\helpers\pydev\pydevd.py", line 1015, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "M:/HKerr/python/DBread/DBread_27_v2/DBread_27.py", line 108, in <module>
TimeB.strftime("%Y-%m-%d %H:%M:%S"),Columns,Host)
File "M:/HKerr/python/DBread/DBread_27_v2\DBread_mdl_27.py", line 222, in MySQLread
count+=1
File "C:\Python27\lib\site-packages\pymysql\connections.py", line 842, in __exit__
self.rollback()
File "C:\Python27\lib\site-packages\pymysql\connections.py", line 793, in rollback
self._read_ok_packet()
File "C:\Python27\lib\site-packages\pymysql\connections.py", line 767, in _read_ok_packet
pkt = self._read_packet()
File "C:\Python27\lib\site-packages\pymysql\connections.py", line 1001, in _read_packet
% (packet_number, self._next_seq_id))
pymysql.err.InternalError: Packet sequence number wrong - got 185 expected 1