Any way to select without causing locking in MySQL?

后端 未结 8 1641
执笔经年
执笔经年 2020-11-22 15:21

Query:

SELECT COUNT(online.account_id) cnt from online;

But online table is also modified by an event, so frequently I can see lock by runn

8条回答
  •  Happy的楠姐
    2020-11-22 15:35

    You may want to read this page of the MySQL manual. How a table gets locked is dependent on what type of table it is.

    MyISAM uses table locks to achieve a very high read speed, but if you have an UPDATE statement waiting, then future SELECTS will queue up behind the UPDATE.

    InnoDB tables use row-level locking, and you won't have the whole table lock up behind an UPDATE. There are other kind of locking issues associated with InnoDB, but you might find it fits your needs.

提交回复
热议问题