首页 > 解决方案 > mysql中等待死锁的默认时间

问题描述

我正在使用以下 mysql 模式:

try:
    print ('111111')
    self.cursor.execute(sql, values)
    print ('222222') # print to see how long timeouts are taking...
except Exception as error:
    # Most likely a deadlock, retry if NumAttemps <= MaxAttempts
    logger.exception(error)
    ...

在另一个 mysql 客户端中,为了模拟死锁,我正在做这样的事情:

begin;
select * from records where id='10.5240-D5CF-3' for update;

这是可行的,因为它会抓住死锁并且mysql代码将进入except块,通常会出现错误:

pymysql.err.InternalError: (1205, 'Lock wait timeout exceeded; try restarting transaction')

有没有办法指定cursor在引发超时错误之前将等待多长时间/或者如果有锁则在它“放弃”之前等待多长时间?两者都由 处理innodb_lock_wait_timeout,还是有多个设置?

标签: mysqlsql

解决方案


推荐阅读