MySQL大量的delete后空间如何回收

今天试验了MySQL (版本 5.5.27) 大量的delete 后空间如何回收问题
一、myisam表
 optimize  table  tablename;   #
二、innodb表(独立表空间)--innodb-file-per-table
a.方法一:optimize  table m;
mysql> delete from m where id =3;
Query OK, 262144 rows affected (11.12 sec)
mysql> optimize  table m  ;
+-------+----------+----------+-------------------------------------------------------------------+
| Table | Op       | Msg_type | Msg_text                                                          |
+-------+----------+----------+-------------------------------------------------------------------+
| stu.m | optimize | note     | Table does not support optimize, doing recreate + analyze instead |
| stu.m | optimize | status   | OK                                                                |
+-------+----------+----------+-------------------------------------------------------------------+
You can make OPTIMIZE TABLE work on other storage engines by starting mysqld with the --skip-new or --safe-mode  option. In this case, OPTIMIZE TABLE is just mapped to ALTER TABLE.
 
我在my.cnf文件[mysqld]下加入里加入skip-new
mysql> optimize  table m ;
Query OK, 360448 rows affected (15.33 sec)
Records: 360448  Duplicates: 0  Warnings: 0
[root@localhost data]# ls -lh stu/
total 30M
-rw-rw---- 1 mysql mysql 8.4K May  6 21:12 m.frm
-rw-rw---- 1 mysql mysql  29M May  6 21:15 m.ibd
[root@localhost data]# ls -lh stu/
total 21M
-rw-rw---- 1 mysql mysql 8.4K May  6 21:15 m.frm
-rw-rw---- 1 mysql mysql  20M May  6 21:16 m.ibd

b.方法二: 使用  alter table  table_name engine=innodb   #删除旧表,建立新表。
[root@localhost data]# ls -lh stu/
total 41M
-rw-rw---- 1 mysql mysql 8.4K May  6 20:44 m.frm
-rw-rw---- 1 mysql mysql  25M May  6 21:04 m.ibd
[root@localhost data]# ls -lh stu/
total 18M
-rw-rw---- 1 mysql mysql 8.4K May  6 21:03 m.frm
-rw-rw---- 1 mysql mysql  17M May  6 21:04 m.ibd
三、innodb 共享表空间:
        5.5 版本及之前的版本,我只用过 mysqldump出 表数据,然后导入到新的库(独立表空间),也就相当于重建库的过程。还有就是建立主从库,在从库上设置 独立表空间(对业务基本不影响)
        各位有好的方法请多多指教!!
-----------------------------------
©著作权归作者所有:来自51CTO博客作者smart818的原创作品,请联系作者获取转载授权,否则将追究法律责任
MySQL大量的delete后空间如何回收
https://blog.51cto.com/huanghualiang/1194315

posted @   ingemar,fang  阅读(389)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示