MySQL AUTOCOMMIT status while using BEGIN and START TRANSACTION -
i need use transaction in project on mysql. i'm not sure if have use mysql_query("set autocommit=0"); or not.
 know have 2 options:
- begin
 - start transaction
 
also have heard 1 of both items not need using autocommit = 0.
 please me know when have use autocommit = 0 actually, begin or start transaction?
thank you.
as explained in the manual:
by default, mysql runs autocommit mode enabled. means execute statement updates (modifies) table, mysql stores update on disk make permanent. change cannot rolled back.
to disable autocommit mode implicitly single series of statements, use
start transactionstatement:start transaction; select @a:=sum(salary) table1 type=1; update table2 set summary=@a type=1; commit;with
start transaction, autocommit remains disabled until end transactioncommitorrollback. autocommit mode reverts previous state.
the manual goes on say:
to disable autocommit mode explicitly, use following statement:
set autocommit=0;after disabling autocommit mode setting
autocommitvariable zero, changes transaction-safe tables (suchinnodborndbcluster) not made permanent immediately. must usecommitstore changes disk orrollbackignore changes.
autocommitsession variable , must set each session. disable autocommit mode each new connection, see description ofautocommitsystem variable @ section 5.1.3, âserver system variablesâ.
begin,begin worksupported aliases ofstart transactioninitiating transaction.start transactionstandard sql syntax , recommended way start ad-hoc transaction.
Comments
Post a Comment