简体   繁体   English

如何锁定InnoDB表中的行?

[英]How to lock rows in an InnoDB table?

I'm a new MySQL user. 我是一个新的MySQL用户。 I create an InnoDB database system. 我创建了一个InnoDB数据库系统。

In my case, I need lock rows if select for update is use. 就我而言,如果使用select for update,我需要锁定行。 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. 我用php连接mySQL数据库。

Can you help me to solve that? 你能帮我解决一下吗?

MySQL will do the row-locking for you automatically. MySQL会自动为你做行锁定。
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 . 但是,如果您坚持这样做,可以使用select ... for update
See: http://dev.mysql.com/doc/refman/5.0/en/innodb-locking-reads.html 请参阅: 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;
select col1, col2 from table1 where col3='test' for update

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM