开发者

MySQLdb error when using cursor.execute()

开发者 https://www.devze.com 2023-01-30 15:49 出处:网络
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:

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:

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 开发者_StackOverflow中文版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()

Thanks in advance


It's a quick fix, but changing innodb_lock_wait_timeout might temporarily defer the "Lock wait timeout exceeded" issue. See doc.

Any chance the MySQL version, engine(s), or config's changed when you "moved servers"?

Reading the results of SHOW ENGINE INNODB STATUS would alert you to any recent locking issues.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消