??????????????£??п????????????DirtyRead???????????????UnrepeatableRead?????????PhantomRead????????????Lostupdate?????????????mysql???????????????
????MySQLInnoDB???????е?????????????????????????????????S??????????????д????X????????????????IS??????????????????IX????????????????????????
??????????RecordLock??????????????????????檔
???????????GapLock??????????????????п??????????????????????????????????????????????????????????
????Next-KeyLock????????????????????y???Next-KeyLock??
???????????£?InnoDB???????????????????£???????Next-KeyLock???????????н??м???????????????Ч?????????????Next-KeyLock??????????????????????????InnoDB????????????????????????е??????????????????RecordLock???????????????????????????????GapLock???????????????????T1??????????????????????????????????????
?????????????????£?InnoDB??Next-KeyLock????????????????????????????£?InnoDB??Index-RecordLock????????????????
????????????????????????????????????????????????????????????????????????????????????????????
????SELECT*FROM...LOCKINSHAREMODE???????????????SELECT*FROM...FORUPDATE????????????????
????SELECT*FROM...????????????????Serializable???????????????????????????????£?????????????????Ч??汾???????????????£?????????β?????汾?????????????e汾????????????????л????????????Next-KeyLock???????????????????
????UPDATE...WHERE??DELETE...WHERE????????????????
????INSERTINTO...??Index-RecordLock??????????????????
?????????????
??????????????????????磨?????????????????????????????????????????????????????????????????????????У???????????????????????????????£?????????????????????????????????????????????????????????????????Щ????????????????????????????????????????Щ?????
????????????pessimisticlocking????????????????????????????????£?
??????????????????????????????ü??????????????exclusivelocking??
???????????????????ü?????????????????????????????????????
??????????????????????????????????????????????
??????????????????ü?????????????????????????????????????????????
?????????????????????Ч??????????????????C/S??????????????????????????????????????????
??????????????????????????????????C/S??á?????Web????HTTP?????????????
?????????????ζ????????????????????????????????????£??????????Web?????????????????????????????????????????????
?????????????????μ???????????????????????鷳??????????
?????????????????£????????ī?????????????????????????????
?????????
????MySQL????autocommit?????С?????ζ?????????????????£??????????????MySQL???????μ?buffer?У????????????????????????????ж??????£??????????????2????????儷??????????????????????????????????Ч??????????????
????mysql> select @@autocommit;
????+--------------+
????| @@autocommit |
????+--------------+
????|            1 |
????+--------------+
????????????
????set autocommit=0;
????or
????[mysqld]
????init_connect='SET autocommit=0' ;
????????????????????? autocommit??????????? commit ???????????
????$db->begin();
????$db->query("SET autocommit=0");
????...
????...
????$db->commit();
???????
????1???????"???autocommit"???????????????? innodb ??????е??????????????????? commit ???? rollback ??????????????????????????? autocommit??????????????? autocommit
????2??????mysql?????????????????mysql??????????????init_connect='SET autocommit=0'?????????????????????κδ???
????If a user has SUPER privilege?? init_connect will not execute??(otherwise if init_connect will a wrong query no one can connect to server).
????Note?? if init_connect is a wrong query?? the connection is closing without any errors and next command will clause 'lost connection' error.