search
Homephp教程php手册解析mysql 表中的碎片产生原因以及清理

解析mysql 表中的碎片产生原因以及清理

Jun 13, 2016 am 11:46 AM
mysqldeletereasonexistdatadocumentclean upoffragmentsblanksurfaceparse

大量删除数据必然会在数据文件中造成不连续的空白空间,而当插入数据时,这些空白空间则会被利用起来 。
对于不同的存储引擎整理碎片的方式不一样。
myisam
可以有以下方式:
mysql> show table status from test like 'testusers'\G
*************************** 1. row ***************************
  ....
           Rows: 3
 Avg_row_length: 45
         Data_free: 40
.....
因为在中间删除,所以留下了空白
mysql> optimize table testusers;
+----------------+----------+----------+----------+
| Table          | Op       | Msg_type | Msg_text |
+----------------+----------+----------+----------+
| test.testusers | optimize | status   | OK       |
+----------------+----------+----------+----------+
1 row in set (0.00 sec)
mysql> show table status from test like 'testusers'\G
*************************** 1. row ***************************
   ...
           Rows: 3
 Avg_row_length: 32
    Data_length: 96
      Data_free: 0
1 row in set (0.00 sec)
在optimize后,Data_free已经变为0.碎片数据被清除。
同样还可以用以下方式,效果和optimize一样
./bin/mysqlcheck  -uroot -proot --socket=./tmp/mysql.sock  -o test testusers
innodb
对于innodb 使用optimize和mysqlcheck都不起作用,可以如下进行
对于小表的话直接用ALTER TABLE table_name ;回收表空间,对于大表就不能直接采用这种方式,因为会造成长时间的锁表。可以采用新建表转移数据,然后删除旧表的形式,然后再重命名表。

另外有个python可以查看innodb表空间信息,可以在网上找哈,用python写的。

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor