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出 表数据,然后导入到新的库(独立表空间),也就相当于重建库的过程。还有就是建立主从库,在从库上设置 独立表空间(对业务基本不影响)
各位有好的方法请多多指教!!
一、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出 表数据,然后导入到新的库(独立表空间),也就相当于重建库的过程。还有就是建立主从库,在从库上设置 独立表空间(对业务基本不影响)
各位有好的方法请多多指教!!
相关文章推荐
- mysql delete表数据后,如何解决空间大小不变的问题?
- MySQL5.7 可以回收(收缩)undo log回滚日志物理文件空间
- 如何向mysql中插入大量数据
- 语言包占用了大量的C盘空间Win7系统语言包如何卸载
- MySQL如何防止delete命令删除数据
- C/C++用new、delete分配回收堆中空间
- 配置数据理解-MySQL-网站如何承载大量数据
- 数据库——MySQL如何查看table(表)占用空间的大小
- mysql delete删除记录数据库空间不减少问题解决方法
- oracle性能如何调整,如何回收表空间碎片
- 常量池在jvm的哪个空间里边?常量池如何触发的垃圾回收
- MYSQL中如何查询设置多大,剩余空间是多少
- MySQL如何判别InnoDB表是独立表空间还是共享表空间
- mysql回收innodb 表空间
- 如何查看MySQL中每张表占用的空间大小
- 教你如何调整Mysql中insert、update、delete的顺序来以提高效率
- mysql delete删除记录数据库空间不减少问题解决方法
- 如何回收Xenserver 删除虚拟机快照后释放的空间
- VMware虚拟磁盘空间过大如何进行回收
- 【故障处理】mysql出现大量slave bin日志,将磁盘空间占满