Wednesday, 11 September 2024

Re-claiming disk space from mysql database

 Just deleting rows from a mysql database does not tend to release disk space.


This method is drastic, but will get the disk space back:


  1. Extract any data you want to keep from the database (we are about to delete all the records)
  2. select max(id) from <table name>;
  3. truncate <table name>;
  4. alter table <table name> auto_increment=<starting id>;
this leaves you an empty database but the ids generated for new rows will be unique from the ones in the original database rows.

No comments:

Post a Comment