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.

Check the table and its storage engine

  1. Connect to the server through SSH.

  2. Open the database client:

    mysql -u db_user -p database_name
  3. Identify the table’s engine:

    SHOW TABLE STATUS LIKE 'table_name';
  4. 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_name

Check 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.