Exclusive lock for Database Transaction Processing

Source: Internet
Author: User

Database Transaction Processing exclusive lock under www.2cto.com make an experiment to verify the effect of the lock Terminal 1, first enter the transaction status and then run the following statement mysql> begin; Query OK, 0 rows affected (0.00 sec) mysql> select * from t1 where id = '3' for update; + ---- + -------- + --------------------- + ------------------- + | id | name | ctime | mtime | + ---- + -------- + hour + --------------------- + | 3 | test | 0000-00-00 00:00:00 | 13:05:41 | + ---- + -------- + -------------------- -+ --------------------- + 1 row in set (0.00 sec) Terminal 2: query the data in the table mysql> select * from t1; + ---- + -------- + --------------------- + ------------------- + | id | name | ctime | mtime | + ---- + -------- + hour + --------------------- + | 1 | neo | 0000-00-00 00:00:00 | 13:00:00 | 2 | zen | 0000-00-00 00:00:00 | 13:00:43 | 3 | test | 0000-00-00 00:00:00 | 13:05:41 | + -- -- + -------- + --------------------- + ------------------- + 3 rows in set (0.00 sec) Add "for update" to query non-lock record www.2cto.com mysql> select * from t1 where id = 2 for update; + ---- + ------ + upper + ------------------- + | id | name | ctime | mtime | + ---- + ------ + ----------------------- + ----------------- + | 2 | zen | 0000-00-00 00:00:00 | 13:00:43 | + ---- + ------ + ------------------- + ----- ---------------- + 1 row in set (0.00 sec) query locked records mysql> select * from t1 where id = 3 for update; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction to query all records. Because the record contains the id = 3, query is not allowed. Mysql> select * from t1 for update; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction test modification record mysql> UPDATE 'T1 'set' name' = 'testa' WHERE 'id' = 3; ERROR 1205 (HY000): Lock wait timeout exceeded; try restarting transaction prompt when ERROR 1205 (HY000) is not displayed, As long as commit and rollback are executed in Terminal 1. the statement in Terminal 2 will run.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.