• 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 没有好的办法
    

  • 相关阅读:
    利用服务器实现疫情查询小系统(Web版+APP)
    第五周总结
    第四周总结
    初试python爬取网页数据
    使用ECharts完成数据可视化
    第三周总结
    第二周总结
    求数组中最大子数组的和
    软工第二周博客作业
    MySQL学习笔记(3)——创建、查看、修改、删除数据库
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350808.html
Copyright © 2020-2023  润新知