Matheus Douglas
Matheus Douglas

Reputation: 468

Why did my free disk space decrease after deleting some rows of a table on MySQL?

I deleted thousands of thousands of rows in a table, but the free space in (C:) decreased from 40 Gb to 15 Gb. What happened? Wasn't it supposed to go up?

I've already restarted the MySQL Server and even my computer, but the problem remains. I'm using Windows 10 and MySQL 8.0

Upvotes: 4

Views: 3845

Answers (1)

Evert
Evert

Reputation: 99533

Removing rows is not a guaranteed way to reclaim free disk space. MySQL tends to store data for tables in a single file, or one file per disk. Generally it just marks rows in this file as deleted, so if you insert new rows after, they can take up this space.

To reclaim disk space, MySQL would have to completely rewrite these data files as it's not really possible to (cheaply) delete some data from the middle of a large file.

One reason I can think of for actually having less space, is that you might have the binlog enabled, but it's hard to know for sure what took this extra space without knowing which file sizes increased.

One way to really reclaim this disk space is to rebuild the entire table from scratch.

Upvotes: 1

Related Questions