Reputation: 841
I have a big InnoDB
table in mysql. The problem is my disk space is almost full. I want to reduce my disk space. If I'll delete some rows from the table and use this command:
optimize TABLE_NAME
then my disk space will be reduced. But I want to drop the table. If I'll drop the table, there is not any table to optimize it! What is the appropriate command to reduce disk space after dropping the InnoDB
table?
Upvotes: 4
Views: 11180
Reputation: 142298
OPTIMIZE TABLE
makes a copy of the table. More specifically it does
Note especially that for a brief time you will have two copies of the table occupying space on disk.
innodb_file_per_table = OFF
, the ibdata
file may expand, but not shrink. Again, this may lead to a failure.Beginning with 5.6.17, OPTIMIZE TABLE
will perform the work in place. However, you must drop and re-add any FULLTEXT
indexes.
DROP TABLE
works in one of these ways:
innodb_file_per_table = OFF
: free up space in ibdata
. But this space is not released to the OS. Instead, it will be reused for inserts, etc, to any table.innodb_file_per_table = ON
: The file taken by the table is promptly released to the OS.But... When I refer to the setting of innodb_file_per_table
, I am referring to the setting when the table was CREATEd
or last ALTERed
, not the current setting.
Upvotes: 1
Reputation: 172448
You can try to configure your server to use innodb_file_per_table, but do make it sure that you have your backup and then drop and restore it. You can run the optimize table
.
You can run to check if the innodb_file_per_table is ON
mysql> show variables like "innodb_file_per_table";
+-----------------------+-------+
| Variable_name | Value |
+-----------------------+-------+
| innodb_file_per_table | ON |
+-----------------------+-------+
1 row in set (0.00 sec)
Upvotes: 5
Reputation: 6844
drop command will free disk space automatically.
Note: Assuming you are using innodb_file_per_table as you are able to free space by optimize table syntax.
Upvotes: 7
Reputation: 2267
Actually to reclaim space after dropping tables in MySQL you should enable Per-Table File in the MySQL configuration. Read more here:
https://dev.mysql.com/doc/refman/5.6/en/innodb-multiple-tablespaces.html
Upvotes: 1