Back

mysql - 为一个大表执行 alter table 操作(修改列类型)

发布时间: 2020-12-05 22:56:00

我们有个表,10G, 想要修改列的话,运行alter table会特别慢, MYSQL会把table 做copy, 那漫长的时间...10 小时 copy了30%....

所以, 按照这个教程: https://stackoverflow.com/a/17015000/445908 来做. 

核心是:
4.1 在当前(waf db)中, 创建一个新表: new_table, 只要结构
4.2 在当前(waf db)中, 为这个新表 alter table
4.3 在当前(waf db)中, 为老表: old_table的内容做导出
4.4 在 test 数据库中(注意是一个新库) ,创建 old_table
4.5 在 test db中, 导入old_table的数据
4.6 在 test db中, rename: old_table -> new_table
4.7 在 test db中, 导出 new_table的内容
4.8 在 waf db中, 导入 new_table 的内容
4.9 在 waf db中, rename new_table -> old_table

Back