MySQL: Reclaiming disk space after data deletion
This documentation is part of the Troubleshooting guide. View the full guide here: MySQL common issues and solutions.
👋 Welcome to the Stackhero documentation!
Stackhero provides a fully managed MySQL cloud service that simplifies deployment and management for production workloads:
- Unlimited connections and data transfers.
- Integrated phpMyAdmin web interface for easy database management.
- Hassle-free updates with one-click upgrades.
- Consistent performance and strong security on a private, dedicated infrastructure.
With Stackhero, you can have a reliable MySQL database ready in just a few minutes. Spend less time on setup and maintenance, and more time building your applications. Try MySQL cloud hosting on Stackhero today.
When data is deleted from a MySQL table, the disk space it occupied is not immediately reclaimed. To recover this space, you can execute the following command:
OPTIMIZE TABLE <table>;
This process creates a temporary table, transfers the data to it, and then replaces the original table. During the optimization process, the table will be locked and temporarily unavailable. The duration of this lock and the overall time required depend on the size of the table. Since this operation is resource-intensive, it is advisable to schedule it during periods of low server activity to minimize any impact on performance and availability.