Home > Database > Mysql Tutorial > 利用硬链接原理秒删MySQL大文件

利用硬链接原理秒删MySQL大文件

WBOY
Release: 2016-06-07 17:31:06
Original
1191 people have browsed it

利用硬链接原理秒删MySQL大文件,当多个文件共同指向同一inode、inode链接数Ngt;1、删除任何一个文件都是巨快

原理:

硬链接基础
当多个文件共同指向同一inode、inode链接数N>1、删除任何一个文件都是巨快
因为、此时删除的仅仅是指向inode的指针
而当N=1时、则不一样了、此时删除的文件相关的所有数据块、所以慢

测试:

root@ # ln stock.ibd stock.id.hdlk
root@ # ls stock.* -l
-rw-rw—- 1 mysql mysql        9196 Apr 14 23:03 stock.frm
-rw-r–r– 2 mysql mysql 19096666112 Apr 15 09:55 stock.ibd
-rw-r–r– 2 mysql mysql 19096666112 Apr 15 09:55 stock.id.hdlk
你会发现stock.ibd的INODES属性变成了2;
下面我们继续来删表。
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: 2011-05-18 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)
1秒不到就删除完成; 也就是DROP TABLE不用再HANG这么久了。
但table是删除了,,数据文件还在,所以你还需要最后数据文件给删除。
root # ll
total 19096666112
-rw-r–r– 2 mysql mysql 19096666112 Apr 15 09:55 stock.id.hdlk
root # rm stock.id.hdlk

最后一步删除原始大文件也可以选择rsync来删除、比rm快多了:rsync秒删大文件 见

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template