您的位置:首页 > 数据库 > MySQL

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

2013-05-06 21:44 375 查看
今天试验了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出 表数据,然后导入到新的库(独立表空间),也就相当于重建库的过程。还有就是建立主从库,在从库上设置 独立表空间(对业务基本不影响
各位有好的方法请多多指教!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  空间 where