MySQL Transactions with Non Transactional Tables

This article explains how MySQL handles transactions that involve a mix of transactional (such as InnoDB) and non-transactional (such as MyISAM) storage engines. You will learn how MySQL behaves during commits and rollbacks in these scenarios, the risks of data inconsistency, and how the database logs these mixed operations.

The Core Behavior of Mixed Transactions

MySQL allows you to write queries that modify both transactional and non-transactional tables within a single START TRANSACTION and COMMIT/ROLLBACK block. However, MySQL cannot enforce ACID (Atomicity, Consistency, Isolation, Durability) compliance across non-transactional tables.

When you mix table types, the statements affecting non-transactional tables are executed and committed immediately to the disk. They do not respect the transactional boundaries.

What Happens During a ROLLBACK?

If a mixed-table transaction is rolled back, MySQL faces a split-state scenario:

  1. Transactional Tables (e.g., InnoDB): All modifications made during the transaction are successfully undone (rolled back), returning the tables to their pre-transaction state.
  2. Non-Transactional Tables (e.g., MyISAM): Modifications cannot be undone. The changes remain permanently written to the database.

The Rollback Warning

Because of this partial rollback, MySQL will complete the rollback operation but generate a specific warning to alert the client:

Warning (Code 1196): Some non-transactional changed tables couldn't be rolled back

This warning indicates that your database is now in a potentially inconsistent state, as only part of the logical transaction was successfully reverted.

What Happens During a COMMIT?

If the transaction finishes without errors and you issue a COMMIT statement:

Autocommit Mode and Mixed Transactions

By default, MySQL runs with autocommit enabled. If you do not explicitly start a transaction, every single SQL statement is treated as a separate transaction.

In this mode: * A statement modifying a non-transactional table commits immediately. * A statement modifying a transactional table also commits immediately. * Mixed-table behavior only becomes a critical issue when you disable autocommit or use explicit START TRANSACTION blocks.

Binary Logging and Replication Implications

MySQL uses the binary log (binlog) to replicate data to follower instances. Mixed-table transactions complicate replication:

Best Practices

To prevent data corruption, inconsistent states, and replication issues, adhere to the following guidelines: