zoukankan      html  css  js  c++  java
  • mysql 表级锁

    表级锁:分为读锁和写锁:
    
    lock   tables   table_name   read;//其他事务只能读,不能加写锁,要等待更新。
     
    SESSION 50 执行:
    mysql> update test set name='ccc' where id=1;
    		 
    		 
    mysql> show full processlist;
    +----+---------+----------------------+--------+---------+------+------------------------------+---------------------------------------+
    | Id | User    | Host                 | db     | Command | Time | State                        | Info                                  |
    +----+---------+----------------------+--------+---------+------+------------------------------+---------------------------------------+
    | 20 | monitor | 115.236.160.82:56186 | NULL   | Sleep   |  162 |                              | NULL                                  |
    | 21 | monitor | 115.236.160.82:56187 | NULL   | Sleep   |  162 |                              | NULL                                  |
    | 23 | monitor | 115.236.160.82:56208 | NULL   | Sleep   |   43 |                              | NULL                                  |
    | 24 | monitor | 115.236.160.82:56209 | NULL   | Sleep   |   43 |                              | NULL                                  |
    | 47 | monitor | 115.236.160.82:54858 | NULL   | Sleep   |   66 |                              | NULL                                  |
    | 48 | monitor | 115.236.160.82:54859 | NULL   | Sleep   |   67 |                              | NULL                                  |
    | 49 | root    | localhost            | DEVOPS | Query   |    0 | init                         | show full processlist                 |
    | 50 | root    | localhost            | DEVOPS | Query   |   27 | Waiting for table level lock | update test set name='ccc' where id=1 |
    +----+---------+----------------------+--------+---------+------+------------------------------+---------------------------------------+
    8 rows in set (0.00 sec)
    
    lock   tables   table_name write;//其他事务不能读
    
    解锁:
    
    unlock  tables;
    
    ---------------------------------------------
    
    行级锁:行锁是对索引加锁
    
    
    
    目前对于表级锁查找持有的thread id 没有好的办法
    

  • 相关阅读:
    500桶酒中有一桶毒酒
    查看docker run参数(亲测实用)
    ubuntu密码忘记-备份
    python sklearn2pmml
    javafx弹窗显示错误堆栈
    Java实现新开一个进程
    MockServer调试通过,本地通过浏览器可以打开对应web网页
    java 实现Put request
    JAVA发送HttpClient请求及接收请求完整代码实例
    我还是很喜欢你
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350808.html
Copyright © 2011-2022 走看看