MySQL uses pt-archiver to archive historical data
Pt-archiver can archive tables to a history database according to specified conditions, and also supports file export, which is very convenient for archiving and cleaning up online historical data.
If you want to archive the data of a table to a table in a historical database, you need to create a table structure in the historical database in advance.
(1) Archive the historical data in the table into the historical data according to the conditions, and generate the archive file locally
# create an archive table in the historical database (192.168.56.102)
Mysql > CREATE TABLE `emp` (
-> `id` int (11) NOT NULL
-> `name` varchar (15) DEFAULT NULL
-> PRIMARY KEY (`id`)
->) ENGINE=InnoDB DEFAULT CHARSET=utf8
Query OK, 0 rows affected (0.60 sec)
# View the source table
Mysql > select * from emp
+-+ +
| | id | name |
+-+ +
| | 10 | Neo |
| | 10036 | test |
| | 10037 | test |
| | 10038 | test |
| | 10039 | test |
| | 10040 | MySQL01 |
| | 10041 | MySQL01 |
| | 10042 | MySQL01 |
| | 100100 | test |
| | 100101 | test |
| | 100103 | test |
| | 100104 | test |
| | 100105 | test |
| | 100106 | test |
| | 100107 | test |
| | 100108 | test |
+-+ +
# Archive data with id less than 200000 to history database and local files
# pt-archiver-- source hobby 192.168.56.101Pendure 3307 id where id-- dest hype 192.168.56.102