Search code examples
mysqllockingmyisam

How to lock a single row


I have a user table with field lastusedecnumber.

I need to access and increment lastusedecnumber.

During that accessing time I need to lock that particular user row (not the entire table).

How do I do this?

The table type is MyISAM.


Solution

  • MySQL uses only table-level locking from MyISAM tables. If you can, switch to InnoDB for row-level locking.

    Here's a link to the MySQL site describing Locks set by SQL Statements for InnoDB tables. http://dev.mysql.com/doc/refman/5.0/en/innodb-locks-set.html