How to check your database for corruption

How to check your database for corruption

Jump to: navigation, search

Database corruption usually occurs as a result of a hardware (especially disk-based) failure, or when a disk becomes full. Typical symptoms are failure on login, with this message displayed:

Session Replace: Table './lms/mdl_sessions2' is marked as crashed and should be repaired

This problem mostly seems to affect MySQL.

MySQL

The problem can be repaired using the mysqlcheck command (the command you type is in bold and we assume the database name is ‘lms’ and its type is MySQL):

#mysqlcheck -u lmsuser -p --auto-repair lms
Enter password:
lms.adodb_logsql                      OK
lms.mdl_assignment                    OK
lms.mdl_assignment_submissions        OK
...
lms.mdl_log
error    : Table './lms/mdl_log' is marked as crashed and should be repaired
...
lms.mdl_sessions2
error    : Table './lms/mdl_sessions2' is marked as crashed and should be repaired

Repairing tables
lms_18_latest.mdl_log                           OK
lms_18_latest.mdl_sessions2                     OK

Your mysql database server must be running when executing the mysqlcheck command. If there are problems with the tables, the auto-repair option will fix them as shown above. Note that the repair process can take a long time to complete. Re-run the command again to double-check that all is OK.

Individual LMS tables can be checked by using MySQL Admin/phpMyAdmin

Individual LMS tables may be repaired using MySQL Admin/PHPMyAdmin as follows:

  1. In the databases section, select the LMS database.
  2. Click the SQL tab, then in the “Run SQL query/queries on database lms” field type
    REPAIR TABLE mdl_tablename
  3. Click the Go button.

For example, to repair the LMS log tables, type

REPAIR TABLE mdl_log

In a similar manner to check the LMS log table, type

CHECK TABLE MDL_LOG

. This will either say OK or tell you what is wrong. For example it may say “Table marked as crashed”.

Other databases

As I said above, this issue normally only occurs with MySQL.

See also