mysql - Why does the database need a lock mechanism?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-18 10:54:59
0
3
690

Why does the database need a lock mechanism? Can you give a detailed example using code? Thank you!

曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(3)
滿天的星座

For example, in a panic buying scenario, 10,000 people grab a product. If there is no lock mechanism, 2,333 people may grab the product. At this time, who are you going to sell to?

小葫芦

The database, like the operating system, is a shared resource used by multiple users. When multiple users access data concurrently, multiple transactions simultaneously access the same data in the database. If concurrent operations are not controlled, incorrect data may be read and stored, destroying the consistency of the database. Locking is a very important technology to achieve database concurrency control. Lock-related exceptions are often encountered in practical applications. When two transactions require a set of conflicting locks and the transaction cannot continue, a deadlock will occur, seriously affecting the normal execution of the application.

There are two basic types of locks in the database: Exclusive Locks (X locks)排它锁(Exclusive Locks,即X锁)共享锁(Share Locks,即S锁) and Share Locks (S locks). When a data object is locked exclusively, other transactions cannot read or modify it. Data objects with shared locks can be read by other transactions, but cannot be modified. The database uses these two basic lock types to control the concurrency of database transactions.

🎜
迷茫

Mainly used to solve concurrency problems and ensure data consistency. There are many tutorials online, here is the address for you:
http://www.cnblogs.com/fanp/p...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!