Home > Database > Mysql Tutorial > MySQL大量的delete后空间如何回收

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

WBOY
Release: 2016-06-07 17:28:43
Original
1417 people have browsed it

今天试验了MySQL (版本 5.5.27) 大量的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.

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出 表数据,然后导入到新的库(独立表空间),也就相当于重建库的过程。

各位有好的方法请多多指教!!

linux

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template