MySQL锁表解决方案(亲测)

1,MySQL5.6版本之前的解决方案:

查询表锁定的SQL语句:

SELECT
  r.trx_id waiting_trx_id,
  r.trx_mysql_thread_id waiting_thread,
  r.trx_query waiting_query,
  b.trx_id blocking_trx_id,
  b.trx_mysql_thread_id blocking_thread
FROM
  information_schema.innodb_lock_waits w
INNER JOIN
  information_schema.innodb_trx b ON b.trx_id = w.blocking_trx_id
INNER JOIN
  information_schema.innodb_trx r ON r.trx_id = w.requesting_trx_id;

示例如下图:
MySQL锁表解决方案(亲测)_第1张图片

2,MySQL5.7版本之后的解决方案:

MySQL5.7之后对锁表做了优化,查询表锁定的SQL语句比较简单,如下:

select * from sys.innodb_lock_waits;

示例如下图:
MySQL锁表解决方案(亲测)_第2张图片
完结!!!

你可能感兴趣的:(MySQL)