Repairing WordPress database connection

Just now tried to access this site and got the dreaded “Error establishing a database connection” splash screen.

Went up to WordPress Support and found this post. Followed the advice given my the moderator and used phpMyAdmin to “Repair” the wp_options table — which worked. But why?

Basically what it looks like happened is that somehow, someway (outside hack? foobarred db edit by WordPress itself? Issue with my my ISP’s filesystem?). The “usual suspect” for this kind of thing is the value for ‘siteurl’ in wp_options. As it turned out only a few minutes later the entire database seems to have got iself in trouble and I was forced to run a repair on the whole thing, again inside phpMyAdmin.

To do this without phpMyAdmin you first should confirm the db status by running the following after logging into the database with the mysql client:

check table wp_options;

Next you need to verify what MySQL database engine type you’re running, for example MyISAM or innoDB.

Do that by going to a mysql prompt and running the following query:

select TABLE_NAME, ENGINE from
where TABLE_SCHEMA = 'mydbname';

This should list out all your tables with the database engine type for each, thus:

| table_name            | engine |
| wp_commentmeta        | MyISAM |
| wp_comments           | MyISAM |
| wp_links              | MyISAM |
| wp_options            | MyISAM |
| wp_postmeta           | MyISAM |
| wp_posts              | MyISAM |
| wp_term_relationships | MyISAM |
| wp_term_taxonomy      | MyISAM |
| wp_terms              | MyISAM |
| wp_usermeta           | MyISAM |
| wp_users              | MyISAM |

If your engine type is MyISAM, you can use the following query to try repairing it:

repair table wp_options;

Check these MySQL doc pages for more.