首页 > 数据库 >Investigating Locks in MySQL

Investigating Locks in MySQL

时间:2024-08-08 14:05:23浏览次数:14  
标签:Locks read lock locks InnoDB MySQL Investigating row

Investigating Locks in MySQL

https://emmer.dev/blog/investigating-locks-in-mysql/

A crash course on locks

MySQL (and most relational databases) have a few different types of locks to limit concurrent access from different sessions, protecting schema and data integrity. In MySQL, specifically:

  • Table locks on either base tables or views limit what sessions can read from or write to the table.

  • Row locks on individual rows limit what sessions can read or update those rows. If a row has a read or a "shared" lock then no session can modify the row until the lock is released, but any session can read the row. If a row has a write or an "exclusive" lock then only the session holding the lock can modify the row.

    Standard SELECT ... FROM statements do not need to obtain row read locks unless the transaction isolation level is set to SERIALIZABLE. That means a row write lock won't prevent row reads from other sessions.

    If a statement that modifies rows (e.g. UPDATE or DELETE) has no suitable index, then InnoDB will obtain a write lock on every row in the table.

  • Metadata locks on objects (schemas, tables, triggers, etc.) limit what sessions can alter the metadata of the database object.

This is not an exhaustive list, but it gives us enough information for the sections below.

 

https://emmer.dev/blog/investigating-locks-in-mysql/

A Comprehensive (and Animated) Guide to InnoDB Locking

1/1/2021

Recently, I had a chance to go deep on InnoDB’s locking mechanisms while attempting to debug some contention in MySQL that only appeared during high-throughput. This post is a culmination of my learnings on how InnoDB locking behaves under common scenarios.

Introduction

InnoDB only has a handful of locking concepts, but their use and behaviour depend greatly on the transaction isolation level that is active for the connection.

…the isolation level is the setting that fine-tunes the balance between performance and reliability, consistency, and reproducibility of results when multiple transactions are making changes and performing queries at the same time. ~ 14.7.2.1 Transaction Isolation Levels

There are four transaction isolation levels for InnoDB (in order of most-to-least strict):

  • SERIALIZABLE
  • REPEATABLE READ (default)
  • READ COMMITTED
  • READ UNCOMMITTED

 

标签:Locks,read,lock,locks,InnoDB,MySQL,Investigating,row
From: https://www.cnblogs.com/lightsong/p/18348836

相关文章

  • MYSQL通过sql语句将select查询出来的数据导出到文件中
    脱离数据库管理工具,想直接将select出来的数据导出到一个文件中。使用sql语句:SELECTfild_nameFROMtable_nameINTOOUTFILE'配置文件夹路径/b.xlsx';说明:配置文件夹路径是mysql配置文件中的配置如果不能顺利使用,可能需要修改配置。一、MYSQL配置1.1......
  • MySQL基础学习1
    标签(空格分隔):MySQLmysql常见的命令语句查看所有的数据库showdatabases;查看数据库:selectdatabase();打开指定的库use库名;查看当前库的所有表showtables;查看其他库的所有表showtablesform库名;创建表createtable表名(列名列类型,......
  • MySQL基础学习2
    标签(空格分隔):MySQL进阶五:分组查询语法:select分组函数,列(要求出现在groupby的后面)from表名【where筛选条件】groupby分组的列表【orderby子句】注意:查询列表必须特殊,groupby后面的字段特点:1、分组查询中的筛选条件分为两类|空格|数据源|位置|关键字|-|-|-|......
  • Mysql基础函数
    标签(空格分隔):MySQL一、MySQL中常见的函数一、字符函数1.length获取参数值的字节个数查看字符长度语句:SHOWVARIABLESLIKE'%char%'2.concat拼接字符串SELECTCONCAT(last_name,'_',first_name)姓名FROM`employees`;3.upper(大写转换)、lower(小写转换)语法:upp......
  • MySQL基础学习4
    标签(空格分隔):MySQLDML语言数据操作语言:插入:insert修改:update删除:delete一、插入语言插入方式1、语法:insertinto表名(列名,...)values(值1,...)插入的值的类型要与列的类型一致或兼容INSERTINTObeauty(id,name,sex,borndate,phone,photo,boyfriend_id)VALUES(13,'......
  • MySQL基础学习3
    标签(空格分隔):MySQL进阶七子查询含义:出现在其他语句中的select语句,称为子查询或内查询外部的查询语句,称为主查询或外查询分类:子查询出现的位置:select后面:仅仅支持标量子查询from后面:支持表子where或having后面(▼)标量子查询:单行(......
  • MySQL基础学习5
    标签(空格分隔):MySQLTCL(事务控制语言)事务:一个或一组SQL语句组成一个执行单元,这个执行单元要么全部执行,要么全部不执行事务的ACID(acid)属性1.原子性(Atomicity)原子性是指事务是一个不可分割的工作单位事务中的操作要么都发生,要么都不发生。2.一致性(Consistency)事务必须......
  • MySQL变量的使用
    目录1.系统变量1.1查看系统变量1.2设置系统变量2.用户自定义变量2.1用户自定义变量赋值2.2查看用户自定义变量3.局部变量3.1局部变量声明3.2局部变量赋值3.3查看局部变量MySQL中的变量分为三大类,系统变量、用户自定义变量、局部变量。1.系统变量系统变量以@@开......
  • 基于JSP和MySQL的小说阅读网站系统
    你好,我是计算机专业的学姐,很高兴和大家分享我的毕业设计——小说阅读网站系统。如果对此有兴趣或任何问题,欢迎随时联系我。开发语言:Java数据库:MySQL技术:JSP+JavaBeans+Servlet工具:常用开发环境(如Eclipse)系统展示首页管理员界面读者个人中心作者个人中心......
  • MySQL this is incompatible with sql_mode=only_full_group_by-错误解决
    mysql执行groupby时遇到下面提示:SELECTlistisnotinGROUPBYclauseandcontainsnonaggregatedcolumn'crm.b.id'whichisnotfunctionallydependentoncolumnsinGROUPBYclause;thisisincompatiblewithsql_mode=only_full_group_by原因:在sql执行时,出现该原......