The data migration method of large database tables, this method is also used when the fields are changed, to prevent the library from being locked and the fastest

CREATE TABLE user_info_temp (
    id bigint(28) NOT NULL AUTO_INCREMENT,
    name varchar(32) NOT NULL COMMENT '名称',
  ) 
  RENAME TABLE user_info TO user_info_old;
  RENAME TABLE user_info_temp TO user_info;


#插入近期几分钟需要的数据,后面再插入之前的数据
 INSERT INTO user_info SELECT * FROM user_info_old old WHERE old.create_time >= '2022-11-24 15:00:00'; 

 #按小时来,不然数据太多,插入时间太长可能造成数据库卡顿
 INSERT INTO user_info SELECT * FROM user_info_old old WHERE old.create_time >= '2022-11-24 00:00:00' and old.create_time < '2022-11-24 01:00:00'; 

Ideas:

  1. Create a temporary table first, which is the same as the original table. If you need to change the attributes of the field, you can also modify it at this time.
  2. Name the original large table as another table, add something old
  3. Then name the temporary table as the original table, so that the data can be migrated quickly and effortlessly
  4. Of course, if the original data needs to be used, first insert the data that may be used recently, and then insert the previous data

Guess you like

Origin blog.csdn.net/Fire_Sky_Ho/article/details/128026253