码迷,mamicode.com
首页 > 数据库 > 详细

MySQL表空间集

时间:2014-09-20 15:09:48      阅读:279      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   使用   ar   strong   for   文件   

--MySQL表空间集
----------------------2014-09-20

1. 收缩ibdata的方法,目前MySQL依然没有提供收缩ibdata的方法,只能重构,下面是5.7的步骤。

Decreasing the Size of the InnoDB Tablespace
Currently, 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表空间集

标签:style   blog   color   io   使用   ar   strong   for   文件   

原文地址:http://www.cnblogs.com/jackhub/p/3983254.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!