mysql碎片整理

来源:互联网 发布:乐视3pro王者荣耀优化 编辑:程序博客网 时间:2024/05/22 06:45

我们在使用mysql的时候,每当我们从表中删除一个数据的时候,都会让这段空间滞空。如果在短时间内删除大量的数据,那么这些留出来的空间比数据库中保留的数据所使用的空间还要大。虽然在mysql插入新的数据时候,mysql会尽最大的可能使用这些空间,但是依然是无法全部重新利用的,所以学会mysql碎片清理是很有用处的

mysql> select table_schema, table_name, data_free, engine     from information_schema.tables where table_schema not in ('information_schema', 'mysql') and data_free > 0;

 
+--------------+-----------------------+-----------+--------+
| table_schema | table_name            | data_free | engine |
+--------------+-----------------------+-----------+--------+
| BK           | comments              |   9437184 | InnoDB |
| BK           | historypwd            |   9437184 | InnoDB |
| ss | app_admin_log         |        434 | MyISAM |
| ss | app_article           |        4434 | MyISAM |
|ss | app_article_category  |        43420 | MyISAM |
| ss | app_config            |        3324 | MyISAM |
| ss | app_convert_key       |       1132 | MyISAM |
 
如上图所示中,data_free是指碎片的空间。
你可以通过这两条语句对数据库进行碎片清理:
 
Optimize table ss.app_article;     //这种方式只支持MyIsam引擎
 
INNODB使用    ALTER  TABLE  table.name EMGINE=’InnoDB’;   //使用之前最好对数据备份
 
学会数据库碎片的处理可以大大的增加数据库利用的空间,现在很多的空间上都限定mysql的数据空间大小,如果超过的话需要加收费用,所以使用碎片处理可以减少费用的支出。
原创粉丝点击