[英]MySQLdb error when using cursor.execute()
I am using python and specifically MySQLdb to fill a database, although a code that was working until recently is throwing up an error after moving servers at work: 我正在使用python,特别是MySQLdb来填充数据库,尽管直到最近工作的代码在移动服务器后仍引发错误:
The code is: 代码是:
cursor.execute("""SELECT Entry, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P FROM evaluation""")
result = cursor.fetchall()
for record in result:
codeno=int(str(record[15]))
status, progress, reprocessing = RepStatus_new.get_status(code=codeno, proj_tag=str(record[16]),cache_dir="cache", prod_type="g1")
cursor.execute("""UPDATE evaluation SET M=%s WHERE A LIKE %s""",(progress, int(str(record[15]))))
and the error that comes up is: 而出现的错误是:
File "mySQLtest.py", line 165, in <module>
cursor.execute("""UPDATE evaluation SET M=%s WHERE A LIKE %s""",(progress, int(str(record[15]))))
File "/usr/lib64/python2.5/site-packages/MySQLdb/cursors.py", line 166, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.5/site-packages/MySQLdb/connections.py", line 35, in defaulterrorhandler
raise errorclass, errorvalue
_mysql_exceptions.OperationalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')
I am not sure where this is going wrong, as I said this code worked until recently. 我不确定这是哪里出了问题,因为我说过这段代码直到最近才起作用。 If anyone has any suggestions they would be much appreciated! 如果有人有任何建议,将不胜感激! (I replaced variables with letters to aid read-ability!) (我用字母替换了变量,以提高可读性!)
The database is connecting correctly, as I can output the "result" after cursor.fetchall() 数据库连接正确,因为我可以在cursor.fetchall()之后输出“结果”
Thanks in advance 提前致谢
It's a quick fix, but changing innodb_lock_wait_timeout
might temporarily defer the "Lock wait timeout exceeded" issue. 这是一个快速解决方案,但是更改innodb_lock_wait_timeout
可能会暂时推迟“超出锁定等待超时”的问题。 See doc . 请参阅doc 。
Any chance the MySQL version, engine(s), or config's changed when you "moved servers"? 当您“移动服务器”时,MySQL版本,引擎或配置是否有可能改变?
Reading the results of SHOW ENGINE INNODB STATUS
would alert you to any recent locking issues. 读取SHOW ENGINE INNODB STATUS
的结果将提醒您最近发生的锁定问题。
Last time I seen this when I "moved servers", it was because of conflicting/duplicate scripts/crons trying to hit the same tables. 上次我在“移动服务器”时看到此消息是因为冲突/重复的脚本/错误试图击中相同的表。
At any rate, you might want to push this over to serverfault. 无论如何,您可能希望将其推到serverfault。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.