mysql数据表插入新的列_如何在庞大的MYSQL数据库表中插入新列?

如果是生产:

pt-online-schema-change emulates the way that MySQL alters tables internally, but it works on a copy of the table you wish to alter. This means that the original table is not locked, and clients may continue to read and change data in it.

pt-online-schema-change works by creating an empty copy of the table to alter, modifying it as desired, and then copying rows from the original table into the new table. When the copy is complete, it moves away the original table and replaces it with the new one. By default, it also drops the original table.

oak-online-alter-table allows for non blocking ALTER TABLE operations, table rebuilds and creating a table’s ghost.

更改表会更慢,但它不会锁定表.

如果不是生产和停机时间可以,请尝试这种方法:

CREATE TABLE contacts_tmp LIKE contacts;

ALTER TABLE contacts_tmp ADD COLUMN ADD processed INT UNSIGNED NOT NULL;

INSERT INTO contacts_tmp (contact_table_fields) SELECT * FROM contacts;

RENAME TABLE contacts_tmp TO contacts, contacts TO contacts_old;

DROP TABLE contacts_old;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值