MySQL大量的delete後空間如何回收

來源:互聯網
上載者:User

今天實驗了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出 表資料,然後匯入到新的庫(獨立資料表空間),也就相當於重建庫的過程。 各位有好的方法請多多指教!!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.