mysql Lock wait timeout exceeded; try restarting transaction

来源:互联网 发布:数据分析做什么的 编辑:程序博客网 时间:2024/04/27 18:48

update 数据库中的一条数据,一直失败报这个错误

update执行后执行 SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;

+----------------------+-------------+-----------+-----------+--------------------+------------+------------+-----------+----------+-----------+
| lock_id              | lock_trx_id | lock_mode | lock_type | lock_table         | lock_index | lock_space | lock_page | lock_rec | lock_data |
+----------------------+-------------+-----------+-----------+--------------------+------------+------------+-----------+----------+-----------+
| 27216515D:0:240256:3 | 27216515D   | X         | RECORD    | `xxxxxxx` | `PRIMARY`  |          0 |    240256 |        3 | 2         |
| 27216502F:0:240256:3 | 27216502F   | X         | RECORD    | `xxxxxxx` | `PRIMARY`  |          0 |    240256 |        3 | 2         |
+----------------------+-------------+-----------+-----------+--------------------+------------+------------+-----------+----------+-----------+

执行SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS; 

+-------------------+----------------------+-----------------+----------------------+
| requesting_trx_id | requested_lock_id    | blocking_trx_id | blocking_lock_id     |
+-------------------+----------------------+-----------------+----------------------+
| 27216515D         | 27216515D:0:240256:3 | 27216502F       | 27216502F:0:240256:3 |
+-------------------+----------------------+-----------------+----------------------+

27216515D 是执行update产生的,同时一个27216502F 应该是早先一步拿到了锁没释放

执行 SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX;

+-----------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+
| trx_id    | trx_state | trx_started         | trx_requested_lock_id | trx_wait_started | trx_weight | trx_mysql_thread_id | trx_query | trx_operation_state | trx_tables_in_use | trx_tables_locked | trx_lock_structs | trx_lock_memory_bytes | trx_rows_locked | trx_rows_modified | trx_concurrency_tickets | trx_isolation_level | trx_unique_checks | trx_foreign_key_checks | trx_last_foreign_key_error | trx_adaptive_hash_latched | trx_adaptive_hash_timeout |
+-----------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+
| 27216502F | RUNNING   | 2016-09-09 12:26:19 | NULL                  | NULL             |         11 |                3192 | NULL      | NULL                |                 0 |                 0 |                9 |                  1024 |              56 |                 2 |                       0 | REPEATABLE READ     |                 1 |                      1 | NULL                       |                         0 |                     10000 |
+-----------+-----------+---------------------+-----------------------+------------------+------------+---------------------+-----------+---------------------+-------------------+-------------------+------------------+-----------------------+-----------------+-------------------+-------------------------+---------------------+-------------------+------------------------+----------------------------+---------------------------+---------------------------+

看到这个事物一直存在,已经两个小时了,好吧,不知道咋来的,先kill掉,在此执行就ok了
附带 SHOW ENGINE INNODB STATUS;能看到事物的更详细的信息

0 0