Mysql – Reclaim disk space after drop table from database in thesql

MySQLmysql-8.0

I have this version of MySQL server:

mysql  Ver 8.0.15 for Linux on x86_64 (MySQL Community Server - GPL)

I use a some large tables. When I truncate database with truncate database <name>, I check the hard disk space and I've noticed my disk space is not reclaimed.

This is more information on my server:

SHOW VARIABLES LIKE 'innodb_file_per_table';
'innodb_file_per_table', 'ON'`

Any idea to resolve this ?

Best Answer

  1. You need to "reorganize/rebuild" the table truncated which can be achieved by below.

    mysql> OPTIMIZE table table_name;

for InnoDB tables, it run under ALTER operation.

reference: https://dev.mysql.com/doc/refman/8.0/en/optimize-table.html