V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
MySQL 5.5 Community Server
MySQL 5.6 Community Server
Percona Configuration Wizard
XtraBackup 搭建主从复制
Great Sites on MySQL
Percona
MySQL Performance Blog
Severalnines
推荐管理工具
Sequel Pro
phpMyAdmin
推荐书目
MySQL Cookbook
MySQL 相关项目
MariaDB
Drizzle
参考文档
http://mysql-python.sourceforge.net/MySQLdb.html
0000zjn
V2EX  ›  MySQL

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

  •  
  •   0000zjn · May 19, 2020 · 6076 views
    This topic created in 2169 days ago, the information mentioned may be changed or developed.

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

    Supplement 1  ·  May 20, 2020

    基本明确了,用的5.7mysql,加注释确实会锁表。至于为什么一直锁住,应该是navicat超时断开连接导致的,更具体原因不清楚,应该是bug类。

    7 replies    2020-05-20 02:45:32 +08:00
    snappyone
        1
    snappyone  
       May 19, 2020 via Android
    是不是加了之后没 commit,100 万就算改列也没这么久
    sagaxu
        2
    sagaxu  
       May 19, 2020 via Android   ❤️ 1
    哪个 db 能把注释存到每一行里?
    Coolha
        3
    Coolha  
       May 19, 2020
    alter table 就会给表加锁,和在哪里改的没关系吧
    zhangysh1995
        4
    zhangysh1995  
       May 19, 2020
    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
        5
    0000zjn  
    OP
       May 20, 2020 via iPhone
    @snappyone 改了之后就提交了,不然后面 kill 什么嘛~
    0000zjn
        6
    0000zjn  
    OP
       May 20, 2020 via iPhone
    @Coolha 目前看是的
    0000zjn
        7
    0000zjn  
    OP
       May 20, 2020 via iPhone
    @zhangysh1995 谢谢!正解
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5773 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 59ms · UTC 01:47 · PVG 09:47 · LAX 18:47 · JFK 21:47
    ♥ Do have faith in what you're doing.