Using Hard links to delete large MySQL files in seconds, when multiple files point to the same inode and inode connections Ngt; 1. deleting any file is extremely fast
Using Hard links to delete large MySQL files in seconds, when multiple files point to the same inode and inode connections Ngt; 1. deleting any file is extremely fast
Principle:
Hard link Basics
When multiple files point to the same inode, inode connections N> 1, deleting any file is extremely fast.
This is because only the pointer to inode is deleted.
When N = 1, it is different. At this time, all data blocks related to the deleted file are slow.
Test:
Root @ # ln stock. ibd stock. id. hdlk
Root @ # ls stock. *-l
-Rw -- 1 mysql 9196 Apr 14 stock. frm
-Rw-r-2 mysql 19096666112 Apr 15 stock. ibd
-Rw-r-2 mysql 19096666112 Apr 15 stock. id. hdlk
You will find that the INODES attribute of stock. ibd is changed to 2;
Next we will continue to delete the table.
Root@127.0.0.1: test 21:44:37> show table status like 'stock' \ G
* *************************** 1. row ***************************
Name: stock
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 49916863
Avg_row_length: 356
Data_length: 17799577600
Max_data_length: 0
Index_length: 1025507328
Data_free: 4194304
Auto_increment: NULL
Create_time: 14:55:08
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.23 sec)
Root@127.0.0.1: test 21:39:34> drop table stock;
Query OK, 0 rows affected (0.99 sec)
The deletion is completed in less than one second, that is, the drop table does not need to be HANG for so long.
But the table is deleted, and the data file is still there, so you still need to delete the last data file.
Root # ll
Total 19096666112
-Rw-r-2 mysql 19096666112 Apr 15 stock. id. hdlk
Root # rm stock. id. hdlk
In the last step, you can select rsync to delete the original large file, which is much faster than rm. For details about how to delete large files in rsync seconds, see