Flex60460
Flex60460

Reputation: 993

How to lock rows in an InnoDB table?

I'm a new MySQL user. I create an InnoDB database system.

In my case, I need lock rows if select for update is use. But even if I've done many search I don't understand how to lock row for all users if this row is loaded by one user.

I use php to connect on mySQL database.

Can you help me to solve that?

Upvotes: 4

Views: 4017

Answers (2)

Johan
Johan

Reputation: 76537

MySQL will do the row-locking for you automatically.
There should be no need to do the row locking yourself.

However if you insist on doing this, you can use a select ... for update.
See: http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html

SELECT counter_field FROM child_codes FOR UPDATE;
UPDATE child_codes SET counter_field = counter_field + 1;

Upvotes: 8

James.Xu
James.Xu

Reputation: 8295

select col1, col2 from table1 where col3='test' for update

Upvotes: 2

Related Questions