This article mainly introduces the analysis and solution of MySQL deadlock to coders. For more information about coders, see the next article. MySQL deadlock is a problem that many programmers often encounter in project development. The following describes the MySQL
seconds. You can see that transaction 0 10248 holds 2 locks, transaction 0 10247 has 2 locks, and 1 waits for lock authorization. The entire database has only these 2 transactions, so the lock that caused the insert wait must have been held by 0 10248.If the T2 INSERT statement continues to execute, the deadlock occurs, and the MySQL information is as follows:AnalysisFirst of all we need to understand the
Label:In MySQL, a row-level lock is not a direct lock record, but a lock index. Indexes are primary key index and non-primary key index Two, if a SQL statement operation primary Key index, MySQL will lock the primary key index, if a statement operation non-primary key index, MySQL will first lock the non-primary key index, and then lock the relevant primary key i
Label: MySQL deadlock check I read a blog about the deadlock check today.Advanced InnoDB Deadlock troubleshooting–what SHOW InnoDB STATUS doesn ' t tell you, and what diagnostics you should be Lo OKing atOne common cause for deadlocks when using InnoDB tables are from the existence of foreign key constraints and the sh
Label:Conditions for forming a deadlockOur MySQL storage engine is InnoDB, from the log, InnoDB actively detect to deadlock, and rollback of a waiting for a transaction. The question is, how did InnoDB know about the deadlock? The intuitive approach is that when two transactions are waiting for each other, when a wait time exceeds one of the set thresholds, one t
Recently, there was a project requirement to ensure that multiple machines did not obtain the same data. later, we found that the Mysql Query statement used select .. forupdate often leads to database deadlocks. the following small series will introduce the selectforupdate process of mysql databases. if you are interested in the deadlock problem of
MySQL deadlock problem is a lot of programmers in the development of the project often encountered problems, the MySQL deadlock and the solution is as follows:
1, MySQL common storage engine lock mechanism
MyISAM and memory using table-level locks (table-level locking)
Bd
coupon SET coup num usr = coup num usr + 1 WHERE coup usr =? and spec ID =? and coup num usr
Deadlock occurs because a statement acquires a lock on a normal index, waits for a primary key lock, and another statement acquires a primary key lock and waits for a non-key index, thus a deadlock occurs.
How to solve the update ... where ... The deadlock problem wit
the transaction.Three. Lock pending viewInvolving an external lock or a table lock, InnoDB does not automatically detect the deadlock, which requires setting the lock wait timeout parameter innodb_lock_wait_timeout to resolve (the settings need to be cautious), this parameter is not only to solve the deadlock problem, in the concurrency, A large number of transactions cannot be suspended immediately with t
, such as select .. for update limit, when other servers execute the same SQL statement, they will automatically wait for the release lock. after the previous server lock is released, the server will be able to query the next 30 data records. If more intelligence is required, oracle supports for update skip locked to skip the lock area, so that the next 30 records that are not locked can be queried immediately without waiting.
The following describes the dea
, inserting the same data concurrently, and a unique key exists in the Insert field.No locks are added during normal insertion, but unique keys are uniquely checked for the unique Key's field, and the record is shared with the lock (S) during the check.When multiple threads add a shared lock (s) to the same row, the shared lock (s) is converted to an exclusive (X) lock, which in turn waits for a deadlock.(2). Update concurrent update, updated fields a
Label:This paper will further explain the locking mechanism of INNODB through the process of solving the deadlock problem in a practical example. Recently, in the project development process, encountered the database deadlock problem, in the process of solving the problem, the author of the MySQL InnoDB engine lock mechanism of understanding gradually deepened.
). Insert and update concurrency, with nonclustered indexes.The deadlock principle is the same as 4.(6) Delete and update concurrency.Principle of the same 2.Deadlock Case Connection:InnoDB Next-key Lock-triggered deadlock:Http://www.cnblogs.com/xhan/p/3701459.htmlDeadlock caused by unique key:Http://www.cnblogs.com/sunss/p/3166550.htmlDelete deadlock in MySQLhtt
The example is as follows: When I used show InnoDB status to check the engine status, I found a deadlock problem: * ** (1) transaction: Transaction 0 677833455, active 0 sec, process no 11393, OS thread ID 278546 starting index read MySQL tables in use 1, locked 1 Lock wait3 lock struct (s), heap size 320 MySQL thread ID 83, query ID 162348740 dcnet03 dcne
Recently, in the project development process, encountered the database deadlock problem, in the process of solving the problem, the author of the MySQL InnoDB engine lock mechanism understanding gradually deepened.
The case is as follows:
The deadlock problem was found when using show InnoDB status to check engine state:
(1) TRANSACTION:TRANSACTION 0 677833455
following two statements SELECT id WHERE coup_usr = ? AND spec_id = ? UPDATE coupon SET coup_num_usr = coup_num_usr + 1 WHERE id = ? AND coup_num_usr ? The first statement finds all the primary key IDs that need to update the rows, and then one more update. In MySQL with InnoDB, the update operation will add row-level locks by default, row-level locks are index-based, and you need to query the MySQL execu
Tags: output ase innodb dead actions htm details recursive MySQL deadlockRecently encountered "TOO deep OR LONG SEARCH in the LOCK TABLE waits-for GRAPH, WE'll roll back following TRANSACTION". Re-review the benefit of a lot of, which the deadlock of the rules, in fact, we have 5 years ago to solve the first version of the second kill scene has been involved, and the idea is very similar, if there is time,
This article introduces the solution case of deadlocks caused by loaddata statements in MySQL to coders. it describes some locking mechanisms in the InnoDB engine data table, you can refer to the deadlocks reported by the next online project to briefly describe the causes, solutions, and related points.
1. Background
This is a project similar to DATA analysis. DATA is completely imported into an InnoDB table using the load data statement. To facilita
1. The lock mechanism of MySQL common storage engineMyISAM and memory with table-level lock (Table-level locking)BDB with page lock (page-level locking) or table-level lock, default to page lockInnoDB supports row-level locks (row-level locking) and table-level locks, which are row-level locks by default2. Various lock featuresTable-level locks: low overhead, fast lock-up, no deadlock, lock granularity, hig
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.