The company's server has added hard disk monitoring. After receiving the alarm, it was confirmed that the mysql file took up a lot of space. Therefore, after confirming which table occupies a relatively large space, some data is deleted, but the hard disk space of the server is not released, and the alarm still exists.
Reasons and solutions:
When using delete
delete, mysql
the data file is not deleted, but the identification bit of the data file is deleted, and the file is not organized, so the space will not be completely released. The deleted data will be saved in a linked list, and when new data is written, mysql will use the deleted space to write again. The deletion operation will bring some data fragments, and it is these fragments that are taking up hard disk space.
- The innodb engine can use the operating system to help reclaim these fragments
- There is no way to recycle the MyISam table by itself, it is to be determined here, and we will see it later
The official recommendation is to use OPTIMIZE TABLE
commands to optimize tables, which will re-use unused space and defragment data files.
The syntax is as follows:
OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [