In order to better optimize MySQL in high concurrency, it is necessary to understand the locking table mechanism when MySQL query is updated.I. OverviewMySQL has three levels of Lock: page level, table level, row level.The MyISAM and memory storage engines use a table-level lock (Table-level locking), and the BDB storage engine uses a page lock (page-levelLocking), but also supports table-level locks; The I
, therefore, it does not have the conditions for generating another deadlock .)
4. how to prevent deadlocks
To prevent deadlocks, we must follow the following principles during the development process:
1. avoid concurrent execution of statements involving data modification.
2. Each transaction is required to lock all the data to be used at a time, otherwise execution is not allowed.
3. define a locking order in advance. all transactions must block the
MySQL lock mechanism details and deadlock Handling Methods
To optimize MySQL in high concurrency, it is necessary to understand the lock table mechanism when MySQL queries an update.
I. OverviewMySQL has three levels of locks: Page, table, and row.The MyISAM and MEMORY storage engines use table-level locking. The BDB s
In order to better optimize MySQL in high concurrency, it is necessary to understand the locking table mechanism when MySQL query is updated.I. OverviewMySQL has three levels of Lock: page level, table level, row level.The MyISAM and memory storage engines use a table-level lock (Table-level locking), and the BDB storage engine uses a page lock (page-levelLocking), but also supports table-level locks; The I
MySQL deadlock causes query resolution bitsCN.com
MySQL deadlock causes query resolution failure
During database maintenance recently, data cannot be stored into the database during data parsing. The reason is that MySQL transactions have deadlocked. I restarted
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
;
[Sql]update Girl set age=29 where id=1;[ERR] 1213-deadlock found when trying to get lock; Try restarting transaction
The InnoDB storage engine detects the cyclic dependency of a deadlock and returns an error immediately.Well, I'm still but time old man!What if it does?There must be no end to the story, I have to think of ways to avoid conflict with the old time, so it!START TRANSACTION;UPDAT
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
Solve a deadlock problem in mysql
Here we are talking about innodb deadlocks!
I have found a lot of other commands on the Internet to view the deadlock information. This can be used later:
Show engine innodb status; (varies with the mysql version)
If there is a deadlock aft
Label:MySQL deadlock problem related knowledge is the main content of this article, we will introduce this part of the content, we hope to be able to help you.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 t
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
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
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
, 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
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
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.
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.