Get the App
SLTechnology News&Howtos  ›  Database  › 

Case sharing of MySQL deadlock

Shulou Source: shulou.com Published: 2022-05-31 18:48:47 09月11日 Update

This article introduces the relevant knowledge of "MySQL deadlock case sharing". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

Two small examples of deadlocks:

Deadlock Case 1

For example, self-increasing deadlocks, general deadlocks are 4 DML statements mutually contained, we can do integration, simplification, so that the deadlock scene becomes complex. Let's do a quick simulation.

create table t8

(c1 int auto_increment,

c2 int default null,

primary key(c1),

unique key (c2)

)ENGINE=InnoDB ;

#session1

Begin;

insert into t8 values(null,10);

#session2

insert into t8 values(null,10);

#session1

insert into t8 values(null,9);

Deadlock Case 2

For example, our difficulty escalation, two delete statements caused by deadlock.

create Table: CREATE TABLE `d` (

`i` int(11) NOT NULL DEFAULT '0',

PRIMARY KEY (`i`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

insert into d values(1);

##session1

mysql> begin;

Query OK, 0 rows affected (0.00 sec)

mysql> select *from d where i=1 lock in share mode;

+---+

| i |

+---+

| 1 |

+---+

1 row in set (0.00 sec)

##session2

mysql> begin;

Query OK, 0 rows affected (0.00 sec)

mysql> select *from d where i=1 lock in share mode;

+---+

| i |

+---+

| 1 |

+---+

1 row in set (0.00 sec)

#session1

mysql> delete from d where i=1;

Query OK, 1 row affected (10.80 sec)

##session2

mysql> delete from d where i=1;

ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction

mysql>

"MySQL deadlock case sharing" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Deadlock case content more knowledge sentence complex practical successful next two examples dilemma scenario reality situation article editing website industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi OPPO Reno Shulou Technology Shulou Tech Info Shulou Information