加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

mysql的INNODB_TRX事务表记录

(2020-07-16 09:10:22)
分类: PHP
INNODB_TRX :
 INNODB_TRX table 包含信息关于每个事务(排除只读事务)当前执行的在InnoDB,包含是否事务是等待一个锁,
 
当事务启动后, SQL语句 事务是正在执行
 
 including whether the transaction is waiting for a lock
 
 
 INNODB_TRX Columns 相关列信息:
 
TRX_ID:
唯一的事务ID号, 内部与InnoDB(从MySQL 5.6开始, 那些IDs 能用被创建用于只读和非锁定事务
 
TRX_WEIGHT:
 
一个事务的权重,反映(但不一定全是确定的计数) 改变的记录数和被事务锁定的记录数。
 
为了释放一个死锁, InnoDB 选择一个具有小权重的事务作为"受害者”回滚。
 
事务改变了非事务表是被认为是严重的相比其他, 无论是被改变的行或者锁定的行
 
TRX_STATE: 事务执行的状态, 允许的值为 RUNNING, LOCK WAIT, ROLLING BACK, and COMMITTING.
 
TRX_STARTED:事务开始时间
 
TRX_REQUESTED_LOCK_ID: lock 的ID 事务当前等待的,如果TRX_STATE 是lock_wait;
 
否则就是NULL. 得到信息关于lock,使用LOCK_ID和INNODB_LOCKS表关联
TRX_WAIT_STARTED:时间 当事务开始等待锁的时间, 如果TRX_STATE is LOCK WAIT;  否则为空
TRX_MYSQL_THREAD_ID: MySQL thread ID,得到细节关于thread, 使用这个列和NFORMATION_SCHEMA PROCESSLIST table的ID进行关联
 
等于
demo:/root# mysql -uroot -p1234567 --socket=/data01/mysql/mysql.sock -e"show processlist"
Warning: Using a password on the command line interface can be insecure.
+-------+------+---------------------+--------+---------+------+----------+---------------------------------------+
| Id    | User | Host                | db     | Command | Time | State    | Info                                  |
+-------+------+---------------------+--------+---------+------+----------+---------------------------------------+
| 63915 | root | 192.168.33.29:56815 | DEVOPS | Sleep     66 |          | NULL                                  |
| 63916 | root | 192.168.33.29:56816 | DEVOPS | Sleep     70 |          | NULL                                  |
| 64307 | root | 192.168.33.29:60037 | DEVOPS | Sleep    413 |          | NULL                                  |
| 64308 | root | 192.168.33.29:60038 | DEVOPS | Sleep    413 |          | NULL                                  |
| 64317 | root | localhost           | DEVOPS | Sleep    937 |          | NULL                                  |
| 64328 | root | localhost           | DEVOPS | Query     13 | updating | delete from aa where username='admin' |
| 64404 | root | localhost           | NULL   | Query      0 | init     | show processlist                      |
+-------+------+---------------------+--------+---------+------+----------+---------------------------------------+
 
TRX_QUERY:事务执行的语句
 
TRX_OPERATION_STATE:事务的当前操作 如果有的话 否则为NULL
 
TRX_TABLES_IN_USE:InnoDB表的数据用于当处理当前的SQL语句
 
TRX_TABLES_LOCKED: InnoDB 表的数量 当前SQL语句有行锁在上面( 因为那些是行锁,不是表锁,表仍旧可以读取和写入通过多个事务m
 
尽管一些记录被锁定)
 
TRX_LOCK_STRUCTS:事务保留的锁的数量
 
TRX_LOCK_MEMORY_BYTES:这个事务在内存中lock结构占据的大小
 
TRX_ROWS_LOCKED:这个事务锁定的记录,这个值可能包含标记为删除的记录,但是物理存在的 但是对于事务不可见
 
TRX_ROWS_MODIFIED: 此事务中修改和插入记录的数目
 
TRX_ISOLATION_LEVEL: 当前事务的隔离级别
 
 
mysql> SELECT * FROM INFORMATION_SCHEMA.INNODB_TRX\G
*************************** 1. row ***************************
                    trx_id: 197239  
                 trx_state: LOCK WAIT
               trx_started: 2016-10-19 12:21:11
     trx_requested_lock_id: 197239:29:3:2
          trx_wait_started: 2016-10-19 12:21:11
                trx_weight: 2
       trx_mysql_thread_id: 64328
                 trx_query: delete from aa where username='admin'  ###等待锁
       trx_operation_state: starting index read
         trx_tables_in_use: 1
         trx_tables_locked: 1
          trx_lock_structs: 2
     trx_lock_memory_bytes: 360
           trx_rows_locked: 1
         trx_rows_modified: 0
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE READ
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 10000
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
*************************** 2. row ***************************
                    trx_id: 197228
                 trx_state: RUNNING
               trx_started: 2016-10-19 12:19:52
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 3
       trx_mysql_thread_id: 64317
                 trx_query: NULL
       trx_operation_state: NULL
         trx_tables_in_use: 0
         trx_tables_locked: 0
          trx_lock_structs: 2
     trx_lock_memory_bytes: 360
           trx_rows_locked: 4
         trx_rows_modified: 1
   trx_concurrency_tickets: 0
       trx_isolation_level: REPEATABLE READ
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 10000
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
2 rows in set (0.00 sec)
注意:
使用这个表帮助诊断性能问题 在有严重并发负载的时间段
 
使用DESCRIBE or SHOW COLUMNS 来查看额外的信息关于表的列 包含数据类型和默认值

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有