Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 887101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:10:31+00:00 2026-05-15T13:10:31+00:00

I am reading up on transactions in MySQL and am not sure whether I

  • 0

I am reading up on transactions in MySQL and am not sure whether I have grasped something specific correctly, and I want to be sure I understood that correctly, so here goes. I know what a transaction is supposed to do, I’m just not sure whether I understood the statement semantics or not.

So, my question is, is anything wrong, (and, if that is the case, what is wrong) with the following:

By default, autocommit mode is enabled in MySQL.

Now, SET autocommit=0; will begin a transaction, SET autocommit=1; will implicitly commit. It is possible to COMMIT; as well as ROLLBACK;, in both of which cases autocommit is still set to 0 afterwards (and a new transaction is implicitly started).

START TRANSACTION; will basically SET autocommit=0; until a COMMIT; or ROLLBACK; takes place.

In other words, START TRANSACTION; and SET autocommit=0; are equivalent, except for the fact that START TRANSACTION; does the equivalent of implicitly adding a SET autocommit=1; after COMMIT; or ROLLBACK;

If that is the case, I don’t understand http://dev.mysql.com/doc/refman/5.5/en/set-transaction.html#isolevel_serializable – seeing as having an isolation level implies that there is a transaction, meaning that autocommit should be off anyway?

And if there is another difference (other than the one described above) between beginning a transaction and setting autocommit, what is it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:10:32+00:00Added an answer on May 15, 2026 at 1:10 pm

    Being aware of the transaction (autocommit, explicit and implicit) handling for your database can save you from having to restore data from a backup.

    Transactions control data manipulation statement(s) to ensure they are atomic. Being “atomic” means the transaction either occurs, or it does not. The only way to signal the completion of the transaction to database is by using either a COMMIT or ROLLBACK statement (per ANSI-92, which sadly did not include syntax for creating/beginning a transaction so it is vendor specific). COMMIT applies the changes (if any) made within the transaction. ROLLBACK disregards whatever actions took place within the transaction – highly desirable when an UPDATE/DELETE statement does something unintended.

    Typically individual DML (Insert, Update, Delete) statements are performed in an autocommit transaction – they are committed as soon as the statement successfully completes. Which means there’s no opportunity to roll back the database to the state prior to the statement having been run in cases like yours. When something goes wrong, the only restoration option available is to reconstruct the data from a backup (providing one exists). In MySQL, autocommit is on by default for InnoDB – MyISAM doesn’t support transactions. It can be disabled by using:

    SET autocommit = 0
    

    An explicit transaction is when statement(s) are wrapped within an explicitly defined transaction code block – for MySQL, that’s START TRANSACTION. It also requires an explicitly made COMMIT or ROLLBACK statement at the end of the transaction. Nested transactions is beyond the scope of this topic.

    Implicit transactions are slightly different from explicit ones. Implicit transactions do not require explicity defining a transaction. However, like explicit transactions they require a COMMIT or ROLLBACK statement to be supplied.

    Conclusion

    Explicit transactions are the most ideal solution – they require a statement, COMMIT or ROLLBACK, to finalize the transaction, and what is happening is clearly stated for others to read should there be a need. Implicit transactions are OK if working with the database interactively, but COMMIT statements should only be specified once results have been tested & thoroughly determined to be valid.

    That means you should use:

    SET autocommit = 0;
    
    START TRANSACTION;
      UPDATE ...;
    

    …and only use COMMIT; when the results are correct.

    That said, UPDATE and DELETE statements typically only return the number of rows affected, not specific details. Convert such statements into SELECT statements & review the results to ensure correctness prior to attempting the UPDATE/DELETE statement.

    Addendum

    DDL (Data Definition Language) statements are automatically committed – they do not require a COMMIT statement. IE: Table, index, stored procedure, database, and view creation or alteration statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading that ActiveRecord Transactions are automatically wrapped around save and destroy
I was reading about mysql transactions and I was under the impression that you
Thanks for reading this. I have 2 MySQL databases - master for writes, slave
Reading PayPal developer documentation (and this is a lot of documentation) I'm not sure
I have a question regarding MySQL commits and transactions. I have a couple of
Hello i have this XML and i want to sort all the MESSAGE/DATA/TRANSACTIONS/TRANSACTION With
I have a problem that involves several machines, message queues, and transactions. So for
I have been reading an interesting statement in http://download.oracle.com/javase/tutorial/jdbc/basics/transactions.html The interesting part is: Catching
I've been reading that some devs/dbas recommend using transactions in all database calls, even
I'm reading the documentation for Google App Engine and stumbled upon something that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.