mysql 归档方案(一次性)

一、 归档流程:

               1. 导出需要的数据

               2. 创建临时表table_tmp

               3. 导入数据到临时表

               4. 修改原始表名为table_bak

               5. 修改临时表为原始表名

二、归档方式对比

  1. select into outfile load data infile 导入导出的方式

    SELECT * FROM student where create_time > '2018-10-01 00:00:00' into  /data/mysql/student.sql

    source  /data/mysql/student.sql

  2. INSERT INTO 直接读取写入的方式

    INSERT INTO student_tmp SELECT * FROM student where create_time > '2019-02-16 00:00:00'

  3. mysql官方自带逻辑备份工具mysqldump

    mysqldump --user=root --host=127.0.0.1 -p --skip-lock-tables --single-transaction --flush-logs --hex-blob --master-data=2 test student --where="create_time > '2019-04-16 00:00:00'" > /data/mysql/student.sql

  4. Percona归档工具pt-archiver

    pt-archiver  \

    --source h=127.0.0.1, u=root, p=123456, D=test, t=student \

    --dest h=127.0.0.1, P=3306,u=root,p=123456, D=test,t=student_tmp \

     --progress 50000 \

    --where "create_time > '2019-02-16 00:00:00'" \

    --bulk-insert \

    --statistics \

    --charset=UTF8 \

    --limit=50000 --txn-size 1000  \

    --no-delete  

    参数说明:

      

猜你喜欢

转载自www.cnblogs.com/Jack1023/p/10906384.html