84669 personnes étudient
152542 personnes étudient
20005 personnes étudient
5487 personnes étudient
7821 personnes étudient
359900 personnes étudient
3350 personnes étudient
180660 personnes étudient
48569 personnes étudient
18603 personnes étudient
40936 personnes étudient
1549 personnes étudient
1183 personnes étudient
32909 personnes étudient
走同样的路,发现不同的人生
给 MySQL 大表加字段的思路如下:
创建一个临时的新表,首先复制旧表的结构(包含索引)
create table new_table like old_table;
给新表加上新增的字段
把旧表的数据复制过来
insert into new_table(filed1,filed2…) select filed1,filed2,… from old_table
删除旧表,重命名新表的名字为旧表的名字
需要注意下,执行第三步的时候,可能这个过程也需要时间,这个时候有新的数据进来,所以原来的表如果有字段记录了数据的写入时间就最好了,可以找到执行这一步操作之后的数据,并重复导入到新表,直到数据差异很小。不过还是会可能损失极少量的数据。
所以,如果表的数据特别大,同时又要保证数据完整,最好停机操作。
percona有在线ddl的工具,原理就是使用临时表加新数据转移触发器,可以用一下
给 MySQL 大表加字段的思路如下:
创建一个临时的新表,首先复制旧表的结构(包含索引)
create table new_table like old_table;
给新表加上新增的字段
把旧表的数据复制过来
insert into new_table(filed1,filed2…) select filed1,filed2,… from old_table
删除旧表,重命名新表的名字为旧表的名字
需要注意下,执行第三步的时候,可能这个过程也需要时间,这个时候有新的数据进来,所以原来的表如果有字段记录了数据的写入时间就最好了,可以找到执行这一步操作之后的数据,并重复导入到新表,直到数据差异很小。不过还是会可能损失极少量的数据。
所以,如果表的数据特别大,同时又要保证数据完整,最好停机操作。
percona有在线ddl的工具,原理就是使用临时表加新数据转移触发器,可以用一下