A damaged database table can cause website errors or make stored information unavailable. From an SSH session, you can use MySQL’s maintenance tools to check a table and, for supported storage engines, attempt a repair.
Before you start
Arrange a maintenance window and take a database backup where possible. You need SSH access, database credentials and appropriate table permissions. Replace db_user, database_name and table_name below with the actual values. The -p option prompts for the password without placing it in the command.
A repair can change or discard damaged data. REPAIR TABLE does not repair InnoDB tables. Do not run myisamchk against files that the database server is using.
Check the table and its storage engine
-
Connect to the server through SSH.
-
Open the database client:
mysql -u db_user -p database_name -
Identify the table’s engine:
SHOW TABLE STATUS LIKE 'table_name'; -
Exit the client with
exit, then check the selected table:mysqlcheck -u db_user -p --check database_name table_name
On MariaDB installations, the tool may be named mariadb-check. Read the result before choosing a recovery method; a successful check does not require a repair.
Repair a MyISAM table
If the table uses MyISAM and a repair is appropriate for the reported damage, run:
mysqlcheck -u db_user -p --repair database_name table_nameCheck the result and test the affected application. If repair fails, or the table uses InnoDB, stop and ask a database administrator to plan recovery or restore a verified backup. Repeated repair attempts are not a substitute for a recovery plan.