Case sharing of MySQL deadlock
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!