0

I'm using InnoDB 5.6.35, and I have a question regarding the correct way to implement MySQL transaction. If I implement the following send it to MySQL in one statement:

START TRANSACTION;

SQL-Statement 1; SQL-Statement 2; ... COMMIT;

Question: Does MySQL automatically issues the Rollback if one of the SQL statements fails? The behavior I've seen is that it looks like MySQL does not commit with the above statements when it encounters a failed operation (even Rollback is not called in my program), but I am not too sure after reading some postings. Do I have to wrap the codes in a stored procedure as suggested by others, and call "Rollback" explicitly in my code?

Can someone help me to clarify this?

1 Answers1

0

https://dev.mysql.com/doc/refman/5.5/en/innodb-error-handling.html Just on some cases it will rollback only the statement that failed.

  • If you run out of file space in a tablespace, a MySQL Table is full error occurs and InnoDB rolls back the SQL statement.
  • A transaction deadlock causes InnoDB to roll back the entire transaction.
  • A duplicate-key error rolls back the SQL statement
  • A row too long error rolls back the SQL statement.
  • Other errors are mostly detected by the MySQL layer of code (above the InnoDB storage engine level), and they roll back the corresponding SQL statement
Mr. bug
  • 366
  • 2
  • 11