mysql innodb_locks table 转储到文件
mysql innodb_locks table dump to file
根据 mysql 关于 InnoDB Transaction and Locking Information page 的参考:
- The data exposed by the transaction and locking tables (INNODB_TRX, INNODB_LOCKS, and INNODB_LOCK_WAITS) represents a glimpse into fast-changing data.
- 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.
所以我想知道是否有办法将这个 info/buffer 写入文件?
我认为没有任何方法可以直接访问您所说的缓冲区。您可以对命名的 INFORMATION_SCHEMA tables 使用 SELECT
查询,它将间接地从这些缓冲区中读取。
另一种方法是每 15 秒将 SHOW ENGINE INNODB STATUS 的输出转储到 MySQL 服务器错误日志中。您可以选择使此状态包含锁定信息。参见 https://dev.mysql.com/doc/refman/5.6/en/innodb-enabling-monitors.html
示例:我启用了带有锁定选项的 InnoDB 锁定监视器。
mysql> set global innodb_status_output_locks=on;
mysql> set global innodb_status_output=on;
然后我创建了一个事务,插入到测试中table。但先不要承诺。
mysql> BEGIN;
mysql> INSERT INTO t VALUES (1,1);
在第二个 window 后,我开始了另一个事务,另一个插入设计为与第一个插入冲突。
mysql> INSERT INTO t VALUES (1,1);
挂起,等待第一个会话持有的锁。
然后跟踪 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
根据 mysql 关于 InnoDB Transaction and Locking Information page 的参考:
- The data exposed by the transaction and locking tables (INNODB_TRX, INNODB_LOCKS, and INNODB_LOCK_WAITS) represents a glimpse into fast-changing data.
- 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.
所以我想知道是否有办法将这个 info/buffer 写入文件?
我认为没有任何方法可以直接访问您所说的缓冲区。您可以对命名的 INFORMATION_SCHEMA tables 使用 SELECT
查询,它将间接地从这些缓冲区中读取。
另一种方法是每 15 秒将 SHOW ENGINE INNODB STATUS 的输出转储到 MySQL 服务器错误日志中。您可以选择使此状态包含锁定信息。参见 https://dev.mysql.com/doc/refman/5.6/en/innodb-enabling-monitors.html
示例:我启用了带有锁定选项的 InnoDB 锁定监视器。
mysql> set global innodb_status_output_locks=on;
mysql> set global innodb_status_output=on;
然后我创建了一个事务,插入到测试中table。但先不要承诺。
mysql> BEGIN;
mysql> INSERT INTO t VALUES (1,1);
在第二个 window 后,我开始了另一个事务,另一个插入设计为与第一个插入冲突。
mysql> INSERT INTO t VALUES (1,1);
挂起,等待第一个会话持有的锁。
然后跟踪 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