MySQL Forums
Forum List  »  General

Is it best practice to lock table for every Mysql query?
Posted by: Caigen Liu
Date: December 20, 2018 11:24AM

This is a question quizzing me:

Assume we use MySQL MyIsam tables and php coding for websites in which the database are frequently read and update.

Now we have a SELECT MySQL query. Usually we lock all tables for READ, run the query, then unlock tables. My question is, can we run the query without lock all tables for READ and in the meantime ensure the results of SELECT is right?

For a website software in which the database tables need frequent read and update, can we only lock tables for WRITE if the MySQL query changes database tables e.g. delete/update/insert? And don't lock tables if the MySQL query is "SELECT"? If this question's answer is "yes", why we need "READ" lock?

Hope any professional opinions and thoughts. Thanks.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.