Autocommit Mode


By default, the system variable AUTOCOMMIT is set to 1, which instructs MySQL to process each database-manipulation statement issued immediately as a single transaction. This is the behavior you have already seen, with an INSERT, UPDATE, or DELETE committed to the database as soon as you issue the command.

Consider this simple UPDATE statement:

 UPDATE PRODUCTS SET price = 5.99 WHERE code = 'MINI'; 


When autocommit mode is turned on, the previous statement is executed as if you had entered the following:

 BEGIN TRANSACTION; UPDATE PRODUCTS SET price = 5.99 WHERE code = 'MINI'; COMMIT; 


By setting the value of AUTOCOMMIT to 0, you disable this feature so that you have to use COMMIT to store any changes madeor use ROLLBACK to discard changessince the beginning of the transaction.

To disable AUTOCOMMIT, use the SET command as shown:

 mysql> SET AUTOCOMMIT=0; Query OK, 0 rows affected (0.00 sec) 





Sams Teach Yourself MySQL in 10 Minutes
Sams Teach Yourself MySQL in 10 Minutes
ISBN: 0672328631
EAN: 2147483647
Year: 2006
Pages: 165
Authors: Chris Newman

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net