MySQL資料表空間集

來源:互聯網
上載者:User

標籤:style   blog   color   io   使用   ar   strong   for   檔案   

--MySQL資料表空間集
----------------------2014-09-20

1. 收縮ibdata的方法,目前MySQL依然沒有提供收縮ibdata的方法,只能重構,下面是5.7的步驟。

Decreasing the Size of the InnoDB TablespaceCurrently, you cannot remove a data file from the system tablespace. To decrease the system tablespace size, use this procedure:1. Use mysqldump to dump all your InnoDB tables, including InnoDB tables located in the MySQL database. As of 5.6, there are five InnoDB tables included in the MySQL database:mysql> select table_name from information_schema.tables where table_schema=‘mysql‘ and engine=‘InnoDB‘;+----------------------+| table_name           |+----------------------+| innodb_index_stats   || innodb_table_stats   || slave_master_info    || slave_relay_log_info || slave_worker_info    |+----------------------+5 rows in set (0.00 sec)      Stop the server.2. Remove all the existing tablespace files (*.ibd), including the ibdata and ib_log files. Do not forget to remove *.ibd files for tables located in the MySQL database.3. Remove any .frm files for InnoDB tables.4. Configure a new tablespace.5. Restart the server.6. Import the dump files.

2. 再看一個官方說明,file-per-table的優勢,同時也指出了ibdata檔案的空間只能被重用,但無法釋放給作業系統。

You can reclaim operating system disk space when truncating or dropping a table. For tables created when file-per-table mode is turned off, truncating or dropping the tables creates free space internally in the ibdata files but the free space can only be used for new InnoDB data.

3. 對於file-per-table的表,回收空間,使用optimize table,實現原理如下面所示,其實就是重建+改名。

You can run OPTIMIZE TABLE to compact or recreate a tablespace. When you run an OPTIMIZE TABLE, InnoDB will create a new .ibd file with a temporary name, using only the space required to store actual data. When the optimization is complete, InnoDB removes the old .ibd file and replaces it with the new .ibd file. If the previous .ibd file had grown significantly but actual data only accounted for a portion of its size, running OPTIMIZE TABLE allows you to reclaim the unused space.

 

MySQL資料表空間集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.