Troubleshooting

Corrupted tables in a MySQL database

Reviewed on 2 min read mysql reparacion

Symptoms

An error that mentions a table doesn't prove it is corrupted. Keep the exact code and message: invalid SQL, permissions, lack of disk space, locks or a missing table each need a different procedure.

Before repairing:

  1. Confirm with a check that the specific table is marked as corrupted.
  2. Identify its engine in phpMyAdmin. REPAIR TABLE works for engines such as MyISAM and, on MariaDB, Aria; it doesn't repair InnoDB.
  3. Keep a backup you can restore. A repair can lock the table or discard damaged data.

Repairing with phpMyAdmin

In phpMyAdmin, select only the confirmed table with a compatible engine and use Repair table. Don't select the whole database as a first step.

Repairing with cPanel

In cPanel > Manage My Databases you may see Repair Database. This action works on the whole database; use it only with a backup available and after confirming that it contains tables this tool can repair.

Repairing over SSH

If you are an advanced user and have SSH access enabled, you can run the repair with the following command:

mysqlcheck -u USUARIO -p BASE TABLA
mysqlcheck -u USUARIO -p --repair BASE TABLA

On MariaDB servers, the equivalent command may be mariadb-check. If the table is InnoDB, the server shows errors of its own or there is no valid backup, stop and contact support; don't force a recovery on the shared service.

Validate after the repair

Keep the full output of the check and the repair. Compare counts and application features against a known reference; a table opening again doesn't prove that no damaged records were discarded.

If the error comes back, investigate disk space, logs and server status with support before repeating the repair. Don't add a scheduled repair task as a substitute for diagnosis, and don't run tools against the physical files of a database in use.

The REPAIR TABLE reference details the engines and limits. For InnoDB, recovery has to be planned according to the error and the backup available.

You may also find useful

Something wrong or out of date? Tell us and we will review it.