autocommit


Background

A transaction is a set of SQL statements that execute as a unit. Either all the statements execute successfully, or none of them have any effect. This is achieved by using the commit and rollback capabilities of MySQL. If all of the statements in the transaction succeed, changes to the record are committed to the database. If an error occurs during the transaction, the changes are rolled back and canceled.

Transactional processing provides stronger guarantees about the outcome of database operations, but requires more overhead in CPU cycles, memory, and disk space. InnoDB is a transaction-safe storage engine.

By default, MySQL runs in autocommit mode, which means that changes made by individual statements are committed to the database immediately to make them permanent. By default, each statement is its own transaction. To perform transactions explicitly, disable autocommit mode and then tell MySQL when to commit or roll back changes.

Objectives

Steps

  1. Create a table
  2. Examine the current SQL mode
  3. Set the autocommit variable
  4. Start a transaction
  5. Roll back a transaction
  6. Start a different transaction
  7. Roll back a transaction
  8. Set the autocommit variable
  9. Start a different transaction
  10. Attempt to roll back
  11. Exit
  12. Congratulations! You have successfully used a MySQL transaction-safe storage engine.