MySQL Forums
Forum List  »  Newbie

Re: lock and transaction
Posted by: Jay Pipes
Date: June 29, 2005 10:12AM

felix wrote:
>
> Don't use (UN)LOCK TABLES with transactional
> tables.
> See
> http://dev.mysql.com/doc/mysql/en/lock-tables.html
>
>

This is incorrect. Gianpaolo, the reason you are seeing the behaviour you are seeing is because the LOCK TABLES and UNLOCK TABLES commands issue an implicit COMMIT under AUTOCOMMIT mode. To remedy the situation, you should use SET @@AUTOCOMMIT=0; before starting your transaction:

SET @@AUTOCOMMIT=0;
START TRANSACTION;
lock table customers WRITE;
UPDATE `customers` SET `Customer Name`='MODIFYcustomer' WHERE `idcustomer`=1;
unlock table;
ROLLBACK;

You can read more about autocommit mode here:

http://dev.mysql.com/doc/mysql/en/innodb-and-autocommit.html

and the implicit COMMIT statements here:

http://dev.mysql.com/doc/mysql/en/innodb-implicit-command-or-rollback.html

Jay Pipes
Community Relations Manager, North America, MySQL Inc.

Got Cluster? http://www.mysql.com/cluster
Personal: http://jpipes.com

Options: ReplyQuote


Subject
Written By
Posted
June 29, 2005 04:23AM
Re: lock and transaction
June 29, 2005 10:12AM
June 29, 2005 11:53AM
June 29, 2005 11:55AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.