How to lock rows in an InnoDB table?

I am a new MySQL user. I am creating an InnoDB database system.

In my case, I need lock lines if the choice to update is used. But even if I did a lot of searching, I don’t understand how to block a row for all users if this row is loaded by one user.

I am using php to connect to mySQL database.

Can you help me solve this?

+4
source share
2 answers

MySQL will automatically lock the rows.
It should not be necessary to lock the strings yourself.

However, if you insist on this, you can use 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; 
+8
source
 select col1, col2 from table1 where col3='test' for update 
+2
source

Source: https://habr.com/ru/post/1380536/


All Articles