简体   繁体   English

mysql innodb_locks 表转储到文件

[英]mysql innodb_locks table dump to file

According to mysql reference about InnoDB Transaction and Locking Information page :根据关于InnoDB 事务和锁定信息页面的mysql 参考:

  1. The data exposed by the transaction and locking tables (INNODB_TRX, INNODB_LOCKS, and INNODB_LOCK_WAITS) represents a glimpse into fast-changing data.事务和锁定表(INNODB_TRX、INNODB_LOCKS 和 INNODB_LOCK_WAITS)公开的数据代表了对快速变化数据的一瞥。
  2. For performance reasons, and to minimize the chance of misleading joins between the transaction and locking tables, InnoDB collects the required transaction and locking information into an intermediate buffer whenever a SELECT on any of the tables is issued.出于性能原因,并且为了尽量减少在事务和锁定表之间误导联接的可能性,每当对任何表发出 SELECT 时,InnoDB 都会将所需的事务和锁定信息收集到中间缓冲区中。

So I'd like to know if there is a way to write this info/buffer into a file?所以我想知道是否有办法将此信息/缓冲区写入文件?

I don't think there's any way to access the buffer you speak of directly.我认为没有任何方法可以直接访问您所说的缓冲区。 You can use SELECT queries against the named INFORMATION_SCHEMA tables, which will read from those buffers indirectly.您可以对命名的 INFORMATION_SCHEMA 表使用SELECT查询,这些表将从这些缓冲区中间接读取。

An alternative is to make the output of SHOW ENGINE INNODB STATUS be dumped to the MySQL Server error log every 15 seconds.另一种方法是每 15 秒将 SHOW ENGINE INNODB STATUS 的输出转储到 MySQL 服务器错误日志。 You can optionally make this status include lock information.您可以选择使此状态包含锁定信息。 See https://dev.mysql.com/doc/refman/5.6/en/innodb-enabling-monitors.htmlhttps://dev.mysql.com/doc/refman/5.6/en/innodb-enabling-monitors.html

Example: I enabled the InnoDB lock monitor with lock options.示例:我使用锁定选项启用了 InnoDB 锁定监视器。

mysql> set global innodb_status_output_locks=on;
mysql> set global innodb_status_output=on;

Then I created one transaction, inserting into a test table.然后我创建了一个事务,插入到一个测试表中。 But don't commit yet.但是不要提交。

mysql> BEGIN;
mysql> INSERT INTO t VALUES (1,1);

In a second window, I begin another transaction, with another insert designed to conflict with the first one.在第二个窗口中,我开始另一个事务,另一个插入设计为与第一个冲突。

mysql> INSERT INTO t VALUES (1,1);

This hangs, waiting for the lock held by the first session.这会挂起,等待第一个会话持有的锁。

Then tail the MySQL error log, to observe the locks:然后尾部 MySQL 错误日志,观察锁:

------------
TRANSACTIONS
------------
Trx id counter 3528210
Purge done for trx's n:o < 3528208 undo n:o < 0 state: running but idle
History list length 814
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 3528209, ACTIVE 30 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 1, OS thread handle 0x70000a4bd000, query id 23 localhost root update
insert into t values (1,1,null,null)
------- TRX HAS BEEN WAITING 30 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 3342 page no 3 n bits 72 index `PRIMARY` of table `test`.`t` trx id 3528209 lock mode S locks rec but not gap waiting
------------------
TABLE LOCK table `test`.`t` trx id 3528209 lock mode IX
RECORD LOCKS space id 3342 page no 3 n bits 72 index `PRIMARY` of table `test`.`t` trx id 3528209 lock mode S locks rec but not gap waiting
---TRANSACTION 3528208, ACTIVE 49 sec
2 lock struct(s), heap size 360, 1 row lock(s), undo log entries 1
MySQL thread id 2, OS thread handle 0x70000a501000, query id 17 localhost root
TABLE LOCK table `test`.`t` trx id 3528208 lock mode IX
RECORD LOCKS space id 3342 page no 3 n bits 72 index `PRIMARY` of table `test`.`t` trx id 3528208 lock_mode X locks rec but not gap

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM