Repairing and optimising database tables

Two different operations that are often confused.

Repair

Fixes a table reporting itself as corrupt – usually after an interrupted write. The symptom is an error naming a specific table and telling you to repair it. In phpMyAdmin, select the table, then choose Repair table from the operations dropdown.

If tables corrupt repeatedly, that is not something to keep repairing. Tell us, because the cause is usually something else – a process being killed for exceeding limits, or a disk problem.

Optimise

Reclaims space left behind by deleted rows. Deleting a hundred thousand rows does not necessarily shrink the file; optimising rebuilds it. Worth doing after a large cleanup, and largely pointless as a routine.

When it actually helps

  • After clearing a large volume of expired sessions or scheduled actions
  • After deleting years of post revisions or logs
  • When a table's overhead is a large proportion of its size – phpMyAdmin shows this

What optimising will not fix

It will not make a slow query fast. Slowness is nearly always a missing index or a query doing too much work, not fragmentation. Optimising a table and finding no difference is the normal outcome – look at the query instead.

Take a backup first

Both operations lock the table while they run, so do them at a quiet time, and export the database first. On a busy shop, a locked table means errors for customers.

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Managing your MySQL databases

Everything to do with databases is in cPanel, in two places: MySQL Databases for creating and...

How databases and database users are named

Database and user names are always prefixed with your cPanel account name and an underscore. You...

Creating a database and a database user

An application needs two things: a database to store data in, and a user with permission to use...

Using phpMyAdmin without breaking anything

phpMyAdmin, in cPanel, gives you direct access to your data. That is useful and it is also the...

Importing a large database

phpMyAdmin has an upload size limit, and a large database import will fail part-way through...