MySQL 在线增加表注释、行注释是否会锁表

2020-05-19 14:33:28 +08:00
 0000zjn

今天给线上一个一百多万的表加注释的时候,表锁住了半小时,最后 kill 解决了。 由于用的是 Navicat,我想知道,在命令行里 alter comment 会不会也会锁表? (我知道改字段类型等是会锁的,但是加个注释而已,不至于吧?)

5020 次点击
所在节点    MySQL
7 条回复
snappyone
2020-05-19 14:53:50 +08:00
是不是加了之后没 commit,100 万就算改列也没这么久
sagaxu
2020-05-19 15:00:35 +08:00
哪个 db 能把注释存到每一行里?
Coolha
2020-05-19 15:57:26 +08:00
alter table 就会给表加锁,和在哪里改的没关系吧
zhangysh1995
2020-05-19 17:31:25 +08:00
ALTER TABLE operations are processed using one of the following algorithms:

COPY: Operations are performed on a copy of the original table, and table data is copied from the original table to the new table row by row. Concurrent DML is not permitted.
不可以并发

INPLACE: Operations avoid copying table data but may rebuild the table in place. An exclusive metadata lock on the table may be taken briefly during preparation and execution phases of the operation. Typically, concurrent DML is supported.
可能加锁,一般可以并发

INSTANT: Operations only modify metadata in the data dictionary. No exclusive metadata locks are taken on the table during preparation and execution, and table data is unaffected, making operations instantaneous. Concurrent DML is permitted. (Introduced in MySQL 8.0.12)
允许并发

https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
0000zjn
2020-05-20 02:36:56 +08:00
@snappyone 改了之后就提交了,不然后面 kill 什么嘛~
0000zjn
2020-05-20 02:45:10 +08:00
@Coolha 目前看是的
0000zjn
2020-05-20 02:45:32 +08:00
@zhangysh1995 谢谢!正解

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/673231

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX