Using Hard links to delete large MySQL files in seconds

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.