1、innodb_lock_wait_timeout
Property |
Value |
Command-Line Format |
--innodb-lock-wait-timeout=# |
System Variable |
innodb_lock_wait_timeout |
Scope |
Global, Session |
Dynamic |
Yes |
Type |
integer |
Default Value |
50 |
Minimum Value |
1 |
Maximum Value |
1073741824 |
以秒为单位的时间一个InnoDB的事务等待行锁之前放弃。默认值是50秒。事务试图访问一行锁的另一个InnoDB事务最多这许多秒等待写访问的行之前发出以下错误:
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> update t set name='ggg' where id = 2; ##innodb_lock_wait_timeout生效
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> show full processlist;
| 4723261 | root | localhost | test | Query | 4 | updating | update t set name='ggg' where id = 2 |
2、lock_wait_timeout
Property |
Value |
Command-Line Format |
--lock-wait-timeout=# |
System Variable |
lock_wait_timeout |
Scope |
Global, Session |
Dynamic |
Yes |
Type |
integer |
Default Value |
31536000 |
Minimum Value |
1 |
Maximum Value |
31536000 |
这个变量指定的超时秒数尝试获取元数据锁。这超时适用于所有语句使用元数据锁。这些包括DML和DDL操作表、视图、存储过程、和存储功能,以及锁表,冲表读锁,和处理程序语句。给定语句可能需要不止一个锁,所以声明有可能阻止超过lock_wait_timeout值报告之前超时错误。锁定超时发生时,ER_LOCK_WAIT_TIMEOUT报道。
mysql> alter table t add index i_name(name); ###lock_wait_timeout生效
ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction
mysql> show full processlist;
| 4723261 | root | localhost | test | Query | 4 | Waiting for table metadata lock | alter table t add index i_name(name) |
ddl操作无法回滚
3、死锁参数:innodb_deadlock_detect
Property |
Value |
Command-Line Format |
--innodb-deadlock-detect |
Introduced |
5.7.15 |
System Variable |
innodb_deadlock_detect |
Scope |
Global |
Dynamic |
Yes |
Type |
boolean |
Default Value |
ON |
这个选项用于禁用死锁检测。在高并发系统中,死锁检测可能导致经济放缓时大量线程等待相同的锁。有时,它可能是更有效的禁用死锁检测和依靠innodb_lock_wait_timeout设置事务回滚时发生死锁。
总结:
innodb_lock_wait_timeout针对innodb事务等待行锁;lock_wait_timeout针对元数据锁;