Note: You are currently viewing documentation for Moodle 2.3. Up-to-date documentation for the latest stable version is available here: How to check your database for corruption.

How to check your database for corruption: Difference between revisions

From MoodleDocs
No edit summary
(Removed flippant comment about MySQL not being a "proper" database. This isn't useful to someone looking for help with database corruption.)
Line 3: Line 3:
  Session Replace: Table './moodle/mdl_sessions2' is marked as crashed and should be repaired
  Session Replace: Table './moodle/mdl_sessions2' is marked as crashed and should be repaired


This problem mostly seems to affect MySQL. Real databases look after you data properly.
This problem mostly seems to affect MySQL.


==MySQL==
==MySQL==

Revision as of 08:56, 3 March 2010

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 './moodle/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 'moodle' and its type is MySQL):

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

Repairing tables
moodle_18_latest.mdl_log                           OK
moodle_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 Moodle tables may be repaired using MySQL Admin/PHPMyAdmin as follows:

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

For example, to repair the Moodle log tables, type REPAIR TABLE mdl_log

Other databases

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

See also