I have problems with concurrent connections. How do i ensure that one query in ran just after another, without queries from another con开发者_高级运维nections coming in between. I'll probably need some kind of locking, but what kind? ..or? transactions?
Run the 2 queries in SERIALIZABLE isolation level - it guarantees that the result from the 2 queries is exactly the same as if they were the only 2 queries performed, by locking every record they access, but without locking the rest of the table/tables.
If you are using the innodb storage engine, you could use transaction to realize what you want. Just execute BEGIN before the both queries and COMMIT after them.
You can use LOCK TABLE
to prevent other users from updating that table.
Link
http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html
精彩评论