Dividing the horizontal part table mysql

One, background

  1. Boss To arrange a division of Zhang Tairong scale, depending on the year is divided into multiple tables.

Second, the level of segmentation

  1. Split level refers to the number of rows in the data table rows split the table over one million rows, it will slow down, then you can put the data in a table split into multiple tables to store.
  2. After defining the rules points table, the same table structure as the original table, query performance will improve.
  3. ·····

Third, step.

  1. Make a backup
  2. Year partition table is created in accordance with (t_user_data_ year)
    . 1  - Create the same original table structure and the partition table 
    2  Create  Table t_user_data_2019 like t_sys_user;
     . 3  Create  Table t_user_data_2018 like t_sys_user;
     . 4  Create  Table t_user_data_2017 like t_sys_user;
     . 5  Create  Table t_user_data_2016 like t_sys_user;
  3. Identify data each year, and insert it into the partition table
    . 1  - to identify data of each year, and inserted into the partition table 
    2  SELECT  *  from t_sys_user WHERE the DATE_FORMAT (the create_time, ' % the Y ' ) =  ' 2017 ' ;
     . 3  the INSERT  the INTO   t_user_data_2017 SELECT  *  from t_sys_user WHERE the DATE_FORMAT (the create_time, ' % the Y ' ) =  ' 2017 ' ;
     . 4  SELECT  *  from t_sys_user WHERE the DATE_FORMAT (the create_time, ' % the Y') = '2018';
    5 INSERT INTO  t_user_data_2018 select * from t_sys_user where DATE_FORMAT(create_time,'%Y') = '2018';
    6 select * from t_sys_user where DATE_FORMAT(create_time,'%Y') = '2019';
    7 INSERT INTO  t_user_data_2019 select * from t_sys_user where DATE_FORMAT(create_time,'%Y') = '2019';
  4. Recording and backup

Guess you like

Origin www.cnblogs.com/wchwch/p/12036099.html