zoukankan      html  css  js  c++  java
  • 找出mysql 中谁持有表锁

    mysql> show processlist;
    +----+------+-----------+------+---------+------+-------+------------------+
    | Id | User | Host      | db   | Command | Time | State | Info             |
    +----+------+-----------+------+---------+------+-------+------------------+
    |  1 | test |           | NULL | Sleep   |    4 |       | NULL             |
    |  2 | root | localhost | NULL | Query   |    0 | init  | show processlist |
    |  3 | test | localhost | test | Sleep   |    6 |       | NULL             |
    +----+------+-----------+------+---------+------+-------+------------------+
    3 rows in set (0.00 sec)
    
    模拟持有的read 锁ID为3,
    
    ID=3:
    mysql> lock table t1 read;
    Query OK, 0 rows affected (0.00 sec)
    
    
    
    mysql>  show processlist;
    +----+------+-----------+------+---------+------+-------+------------------+
    | Id | User | Host      | db   | Command | Time | State | Info             |
    +----+------+-----------+------+---------+------+-------+------------------+
    |  1 | test |           | NULL | Sleep   |    2 |       | NULL             |
    |  2 | root | localhost | NULL | Query   |    0 | init  | show processlist |
    |  3 | test | localhost | test | Sleep   |   26 |       | NULL             |
    |  4 | test | localhost | NULL | Sleep   |    6 |       | NULL             |
    +----+------+-----------+------+---------+------+-------+------------------+
    4 rows in set (0.00 sec)
    
    
    启用Id4的回话:
    mysql> use test;
    Reading table information for completion of table and column names
    You can turn off this feature to get a quicker startup with -A
    
    Database changed
    mysql> insert into t1 values(3);
    
    
    
    mysql> show engine innodb statusG
    *************************** 1. row ***************************
      Type: InnoDB  --数据库引擎类型 InnoDB
      Name: 
    Status: 
    =====================================
    2015-03-12 07:27:33 7f53861e7700 INNODB MONITOR OUTPUT
    =====================================
    Per second averages calculated from the last 8 seconds  ---最近8秒每秒平均计算
    -----------------
    BACKGROUND THREAD
    -----------------
    srv_master_thread loops: 2 srv_active, 0 srv_shutdown, 432 srv_idle
    srv_master_thread log flush and writes: 434
    ----------
    SEMAPHORES
    ----------
    OS WAIT ARRAY INFO: reservation count 3
    OS WAIT ARRAY INFO: signal count 3
    Mutex spin waits 1, rounds 30, OS waits 1
    RW-shared spins 2, rounds 60, OS waits 2
    RW-excl spins 0, rounds 0, OS waits 0
    Spin rounds per wait: 30.00 mutex, 30.00 RW-shared, 0.00 RW-excl
    ------------
    TRANSACTIONS               -----事务信息
    ------------
    Trx id counter 15624
    Purge done for trx's n:o < 15126 undo n:o < 0 state: running but idle
    History list length 26
    
    
    LIST OF TRANSACTIONS FOR EACH SESSION:   --列出了每个SESSION的事务
    
    ---TRANSACTION 0, not started
    MySQL thread id 2, OS thread handle 0x7f53861e7700, query id 112 localhost root init
    show engine innodb status
    
    ---TRANSACTION 0, not started
    mysql tables in use 1, locked 1
    MySQL thread id 4, OS thread handle 0x7f5386165700, query id 75 localhost test Waiting for table level lock
    insert into t1 values(3)
    
    ---说明thread id =4 执行的sql是insert into t1 values(3) 正在等外锁
    
    
    ---TRANSACTION 15623, ACTIVE 319 sec
    mysql tables in use 1, locked 1
    1 lock struct(s), heap size 360, 0 row lock(s)  ---thread id=3 持有一个锁结构
    MySQL thread id 3, OS thread handle 0x7f53861a6700, query id 38 localhost test cleaning up
    --------
    FILE I/O
    --------
    I/O thread 0 state: waiting for i/o request (insert buffer thread)
    I/O thread 1 state: waiting for i/o request (log thread)
    I/O thread 2 state: waiting for i/o request (read thread)
    I/O thread 3 state: waiting for i/o request (read thread)
    I/O thread 4 state: waiting for i/o request (read thread)
    I/O thread 5 state: waiting for i/o request (read thread)
    I/O thread 6 state: waiting for i/o request (write thread)
    I/O thread 7 state: waiting for i/o request (write thread)
    I/O thread 8 state: waiting for i/o request (write thread)
    I/O thread 9 state: waiting for i/o request (write thread)
    Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
     ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
    Pending flushes (fsync) log: 0; buffer pool: 0
    214 OS file reads, 5 OS file writes, 5 OS fsyncs
    0.00 reads/s, 0 avg bytes/read, 0.00 writes/s, 0.00 fsyncs/s
    -------------------------------------
    INSERT BUFFER AND ADAPTIVE HASH INDEX
    -------------------------------------
    Ibuf: size 1, free list len 0, seg size 2, 0 merges
    merged operations:
     insert 0, delete mark 0, delete 0
    discarded operations:
     insert 0, delete mark 0, delete 0
    Hash table size 276671, node heap has 0 buffer(s)
    0.00 hash searches/s, 0.00 non-hash searches/s
    ---
    LOG
    ---
    Log sequence number 1685701
    Log flushed up to   1685701
    Pages flushed up to 1685701
    Last checkpoint at  1685701
    0 pending log writes, 0 pending chkp writes
    8 log i/o's done, 0.00 log i/o's/second
    ----------------------
    BUFFER POOL AND MEMORY
    ----------------------
    Total memory allocated 137363456; in additional pool allocated 0
    Dictionary memory allocated 68091
    Buffer pool size   8191
    Free buffers       7994
    Database pages     197
    Old database pages 0
    Modified db pages  0
    Pending reads 0
    Pending writes: LRU 0, flush list 0, single page 0
    Pages made young 0, not young 0
    0.00 youngs/s, 0.00 non-youngs/s
    Pages read 197, created 0, written 1
    0.00 reads/s, 0.00 creates/s, 0.00 writes/s
    No buffer pool page gets since the last printout
    Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
    LRU len: 197, unzip_LRU len: 0
    I/O sum[0]:cur[0], unzip sum[0]:cur[0]
    --------------
    ROW OPERATIONS
    --------------
    0 queries inside InnoDB, 0 queries in queue
    0 read views open inside InnoDB
    Main thread process no. 26975, id 139996673111808, state: sleeping
    Number of rows inserted 0, updated 0, deleted 0, read 0
    0.00 inserts/s, 0.00 updates/s, 0.00 deletes/s, 0.00 reads/s
    ----------------------------
    END OF INNODB MONITOR OUTPUT
    ============================
    
    1 row in set (0.00 sec)
    

  • 相关阅读:
    事件
    js定时器
    js动画
    oop面向对象编程
    26 正则表达式
    25 异常处理
    javascript操作select的一些基本方法总结
    一个select 列子的思考
    jquery中 toggleClass方法的一种用法
    模拟TAB 采用 attachEvent 遇到的IE兼容问题
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13351769.html
Copyright © 2011-2022 走看看