MySQL
  Home arrow MySQL arrow Page 7 - Using Transactions In MySQL (Part 1)
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MYSQL

Using Transactions In MySQL (Part 1)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 55
    2003-11-03

    Table of Contents:
  • Using Transactions In MySQL (Part 1)
  • Money, Money, Money...
  • The Acid Test
  • Turning the Tables
  • A Question of Commitment
  • Rules of the Game
  • Artificial Intelligence
  • Time Out

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Using Transactions In MySQL (Part 1) - Artificial Intelligence


    (Page 7 of 8 )

    By default, MySQL operates in what is known as "autocommit mode". Simply, this means that MySQL treats every single SQL command as a single-statement transaction, and internally issues a COMMIT after each query to save it to disk. If this is not what you require, you can turn this feature off, by setting the special AUTOCOMMIT variable to 0, as below:

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


    Once this is done, you will need to explicitly issue a COMMIT after every command to have its modifications saved to disk. A failure to do so will result in all your changes automatically being rolled back when you exit the session.

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

    mysql> SELECT * FROM users;
    +----+------+------------------+
    | id | name | pass |
    +----+------+------------------+
    | 3 | alan | 5af23f026beddb81 |
    | 4 | john | 2ca0ede551581d29 |
    +----+------+------------------+
    2 rows in set (0.00 sec)

    mysql> INSERT INTO users (name, pass) VALUES ('tim', PASSWORD('hoo'));

    Query OK, 1 row affected (0.01 sec)

    mysql> INSERT INTO users (name, pass) VALUES ('jim',
    mysql> PASSWORD('i283kh'));
    Query OK, 1 row affected (0.00 sec)

    mysql> SELECT * FROM users;
    +----+------+------------------+
    | id | name | pass |
    +----+------+------------------+
    | 3 | alan | 5af23f026beddb81 |
    | 4 | john | 2ca0ede551581d29 |
    | 14 | tim | 7ae94f60221f748f |
    | 15 | jim | 342cc9873ccd6d02 |
    +----+------+------------------+
    4 rows in set (0.01 sec)

    mysql> exit

    -- reconnect --

    mysql> SELECT * FROM users;
    +----+------+------------------+
    | id | name | pass |
    +----+------+------------------+
    | 3 | alan | 5af23f026beddb81 |
    | 4 | john | 2ca0ede551581d29 |
    +----+------+------------------+
    2 rows in set (0.00 sec)

    You can always restore the default setting by setting the AUTOCOMMIT variable back to 1, as below:

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

    Obviously, the AUTOCOMMIT variable has no impact on non-transactional table types like MyISAM; every change made to those tables is saved to disk immediately and cannot be rolled back.

    More MySQL Articles
    More By icarus, (c) Melonfire


       · Thank you for this article. I wish I could look at Part 2 - but I cannot find it. ...
       · http://www.devshed.com/c/a/MySQL/Using-Transactions-In-MySQL-Part-2Aruna...
     

       

    MYSQL ARTICLES

    - Null and Empty Strings
    - MySQL Server Tuning Tips and Tricks
    - MySQL Query Optimizations and Schema Design
    - MySQL Benchmarking Tools and Utilities
    - MySQL Benchmarking Concepts and Strategies
    - Take Some Load off MySQL with MemCached
    - MySQL Table Prefix Changer Tool in PHP
    - Using the SIGNAL Statement for Error Handling
    - Error Handling Examples
    - Error Handling
    - Completing a Search Engine with MySQL and PH...
    - Paginating Result Sets for a Search Engine B...
    - Building a Search Engine with MySQL and PHP 5
    - Using Boolean Operators for Full Text and Bo...
    - PHP, MySQL and the PEAR Database

     
    Application Delivery: Everything You Wanted to Know, but Didn`t Know You Needed to Ask
    A comprehensive guide to examining the topics of Wide-area Data Services and app....

     
    Best Practices: Safe and Secure Hardware Asset Recovery
    Companies increasingly must meet EPA and local requirements for the disposal of ....

     
    Managing SSL Security in Multi-Server Environments
    Read this white paper to learn how to simplify management of your organization's....

     
    Open Source Security Myths
    Open Source Software (OSS) is computer software whose source code is available t....

     
    Power and Cooling Capacity Management for Data Centers
    This paper describes the principles for achieving power and cooling capacity man....

     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT