Transacciones

¿Cuando utilizar MyISAM y cuando InnoDB?

Transacciones

UPDATE cuentas SET saldo = saldo - 100 WHERE id_cliente = 1;
UPDATE cuentas SET saldo = saldo + 100 WHERE id_cliente = 2;

Gestión de transacciones

Isolation

Isolation levels in MySQL

Ejemplos de transacciones

Ejemplos de problemas del acceso concurrente

_____________________________________________________________________________

MySQL:

Transaction

Transactions are atomic units of work that can be committed or rolled back. When a transaction makes multiple changes to the database, either all the changes succeed when the transaction is committed, or all the changes are undone when the transaction is rolled back.

Database transactions, as implemented by InnoDB, have properties that are collectively known by the acronym ACID, for atomicity, consistency, isolation, and durability.

 START TRANSACTION, COMMIT, and ROLLBACK Statements

To disable autocommit mode explicitly, use the following statement:

SET autocommit=0;

To disable autocommit mode implicitly for a single series of statements, use the START TRANSACTION statement:

START TRANSACTION;
SELECT @A:=SUM(salary) FROM table1 WHERE type=1;
UPDATE table2 SET summary=@A WHERE type=1;
COMMIT;

With START TRANSACTION, autocommit remains disabled until you end the transaction with COMMIT or ROLLBACK. The autocommit mode then reverts to its previous state.

SAVEPOINT, ROLLBACK TO SAVEPOINT, and RELEASE SAVEPOINT Statements

Transaction Isolation Levels

InnoDB offers all four transaction isolation levels described by the SQL:1992 standard: READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, and SERIALIZABLE. The default isolation level for InnoDB is REPEATABLE READ.

SET TRANSACTION Statement

¿Se puede cambiar la configuración del aislamiento por defecto de MySQL? ¿Cómo se hace?

Deja un comentario