如何锁定MySQL或phpmyadmin中的表? [英] how can i lock tables in MySQL or phpmyadmin?

查看:234
本文介绍了如何锁定MySQL或phpmyadmin中的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为排队系统使用一张桌子.该表将不断更新.

I need to use a table for a queuing system. The table will be constantly be updated.

例如,我网站上的多个用户将添加他们的文件以供处理,我听说当多个用户同时进行更新时,表将变得无响应或类似的情况.

For example, multiple users on my website, will add their files for process, and I heard that when updates occur simultaneously from multiple users, the table becomes non responsive or something like that.

那么在这种情况下我需要锁定表吗?如何将锁应用于mysql表?

so do I need locking tables in this situation ? how do i apply a lock to a mysql table ?

推荐答案

同时执行多个更新时,您将陷入僵局.诸如InnoDB之类的引擎将检测到该错误并导致您的事务之一失败(您可以重试,但只能重试整个事务).

When you do several updates at once, you can get into a deadlock situation. Engines such as InnoDB will detect this and fail one of your transactions (You can retry, but only the whole transaction).

您可以通过表锁定来避免这种情况,但这会降低并发性.

You can avoid this by table locking, but it reduces concurrency.

MyISAM之类的引擎(无论如何都不支持MVCC或事务)无论如何都隐式地使用表锁定.这样的表锁仅在查询期间存在.在不再需要该表之后,它们会很快自动释放(不一定要尽快,但很快)

Engines such as MyISAM (which does not support MVCC or transactions anyway) use table locking implicitly anyway. Such table locks exist only for the duration of a query; they're automatically released soonish after the table isn't needed any more (not necessarily as soon as possible, but quite soon)

除非您确实需要使用LOCK TABLE,否则我建议您不要使用LOCK TABLE.如果遇到僵局,请重试该事务.

I recommend you do not use LOCK TABLE unless you feel you really need to; if you get a deadlock, retry the transaction.

这篇关于如何锁定MySQL或phpmyadmin中的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆