no way to alter column comment only?

在尝试更改大量数据表中某列的注释时,遇到MySQL只能通过重定义列定义来改变comment的情况,这会导致Lockwaittimeoutexceeded错误。解决方法是完整地指定新的列定义,包括所有属性。尽管这不是一个直接的解决方案,但这是MySQL的现行规定,需要在操作时注意避免长时间锁定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

想要改一个数量量很大的表的某个字段的comment, 结果发现似乎没有办法只改comment,而必须把column definition 重新定义一遍:

stackOverFlow : Mysql alter comment column only

MySQL specification :

For column definition changes using CHANGE or MODIFY, the definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward. Suppose that a column col1 is defined as INT UNSIGNED DEFAULT 1 COMMENT ‘my column’ and you modify the column as follows, intending to change only INT to BIGINT:

ALTER TABLE t1 MODIFY col1 BIGINT;

That statement changes the data type from INT to BIGINT, but it also drops the UNSIGNED, DEFAULT, and COMMENT attributes. To retain them, the statement must include them explicitly:

ALTER TABLE t1 MODIFY col1 BIGINT UNSIGNED DEFAULT 1 COMMENT 'my column';

结果等于把整个表都刷了一遍,导致Lock wait timeout exceeded。目前没有找到很好的办法来避免这种情况

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qq_23204557

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值