Number of billions of dollars mysql database single table, the data table storing backup 66GB occupancy situation, delete, rollback record

 

A rookie, just record their own ideas and practices, if there is a better solution can comment learn from each other;

Since the beginning of the project design time, design cache synchronization history table; then after a period of time, the amount of data has reached more than 10 million 200 million; about the size of 66GB; now need to delete data, and even completely deleted no problem, but also to write just in case the backup and rollback scripts;

Single table data amount and size of the fields and rows as follows :( after data_length field tables database query table information 1024 is divided by three GB; this amount of data count (*) even if the time-out is also max_execution_time = 30000)

 

Backup and execute the script: think of way is this to the table cache_his remane to backup library; then like to create a new table;

Rollback script is: create a new table like delete, and then back up the table and then rename the library to the official repository;

For example: you want to delete and table backup is cache_his;

Backup and delete the effect of the script: (use between databases and tables dot () connections.)

RENAME TABLE official database table name TO new backup backup database table name;.. The effect is to delete the data in Table formal library and cut to the backup repository;

.cache_his to officially rename table database backup repository .new_copy_cache_his; 

Then create a different table results:

create table a formal library .cache_his IIKE backup library .new_copy_cache_his;

Here and delete the backup is complete;

If you need to roll back problem, just delete the new table cache_his; then the same method to officially rename the library to the backup library;
for example:

drop table cache_his; delete the new table, the rename

rename table backup library .new_copy_cache_his to a formal library .cache_his to

 

This allows relatively rapid completion of the single table large amounts of data backup and delete the rollback; a rookie, just record their own ideas and practices, if there is a better solution can comment learn from each other;

Published 301 original articles · 197 won praise · views 270 000 +

Guess you like

Origin blog.csdn.net/boss_way/article/details/102782697