??????t???
????????????????????????mysql???????????????????MySQL??????autocommit???????????????????????2?????MySQL????????????????
????mysql> set autocommit = 0;
????Query OK?? 0 rows affected (0.01 sec)
????mysql> select @@autocommit;
+--------------+
| @@autocommit |
+--------------+
|            0 |
+--------------+
1 row in set (0.00 sec)
Connect a:
mysql> begin;
Query OK?? 0 rows affected (0.00 sec)
mysql> select age from users where id =1 for update;
+-----+
| age |
+-----+
|  24 |
+-----+
1 row in set (0.00 sec)
mysql> update users set age = 25 where id =1;
Query OK?? 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0
mysql> commit;
Query OK?? 0 rows affected (0.01 sec)
Connect b: ??a?????δ???????
mysql> select * from users where id =1 for update;
ERROR 1205 : Lock wait timeout exceeded; try restarting transaction
mysql> update users set age = 22 where id =1;
ERROR 1205 : Lock wait timeout exceeded; try restarting transaction
????connectb?????connecta?????????У???????????
???????????У????SELECT...FORUPDATE??LOCKINSHAREMODE????????????????????У????SELECT...????????
????MySQLselect…forupdate??RowLock??TableLock
???????????????????select…forupdate????????????????????????????Щ???????MySQLInnoDB???Row-LevelLock????????С???????????????/??????MySQL??????Rowlock(??????????????)??????MySQL???????TableLock(?????????????????)
?????????????????????????????????洢???????????м???????????????MySQLServer????й?????????????ù?????У?MySQL?????Щ???????MySQLServer?????????????????????????unlock_row??????????????????????????(Υ?????????Э??????)???????????????????????????????????????????????????????????????????????????????MySQL?????Ч??????Υ???淶??
????????????????????MySQL??????????RR??????????????????????????????????????????????????????MySQLServer???????????????????????????????????Щ?е????????????????????????????
?????????
??????????????????????“??????????”??????????????????????????????????Ч????棬?????????????????????????????????????????????????????
?????????????????????????????????????????????????????????????????????????л?????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????????????????????????????????????????????????
???????????????????????????????????????????????С????????????????????????????????????????????????????????????????????????????????????????????????????????????y??????????y??????????????