Wednesday, May 11, 2011

MySQL crashed and nodes display "n/a"

MySQL crashed due to a lack of hard drive space. More hard drive space was allocated and MySQL was restarted. For a moment, the site appeared to be fine. A minute later, everywhere a node was suppose to display, "n/a" appeared instead.

I reviewed the MySQL database using phpMyAdmin to see if I could find node content. When I viewed the node_revisions table, an error message displayed that indicated that the table needed to be repaired.

Note: A better way to find tables that need repair is to view the structure of the entire database. A table that needs repair doesn't display records, type, collation, etc. It will display "in use" instead.

Usually in a table view, a Repair table link is available under the Operations tab, but in this case it wasn't available. I used the MySQL Client to run the the repair table command: repair table node_revisions;*

That did the trick. The node content displayed and the site was back up - crisis managed.

One other problem occurred regarding one particular node. The node showed in the Content list, but you couldn't view or edit the node and it threw a 404 error. When I check the database, the node existed in the node table and node content existed in the node_revisions table.

The problem was that in the node table, the vid (version id) for that node was 0 instead of the vid of the last revision in node_revisions. I searched for the nid (node id) in the node_revisions table. I sorted the results by vid and copied the last vid number. I searched for the nid in the node table and replaced the vid with the number I copied.

The node was accessible again and the content was back.

So, if this happens to you:
  1. Review your database structure in phpMyAdmin and look for tables that show "in use." Use the MySQL command: repair table tablename; in the MySQL command line.*
  2. Search the node table for vid = 0. For each node that has a vid of 0, search for the nid in the node_revisions table and copy and replace the vid in the node table.
*Before you can use the REPAIR TABLE MySQL command, you have to use the database

No comments:

Post a Comment