Error establishing a database connection

That was the message when I went to my home page.  This site is implemented using WordPress.  Since I had not changed a thing, and as the site was working fine a couple of hours before this, a mild panic set in.  A quick check of the wp-config.php file and an SSH login to the server verified that the login credentials were correct, since I could connect to the database through the command line.

“How To Fix a Crashed MySQL Table”

A database backup failed with the dreaded message that the wp_options table had crashed.  Frantic googling revealed that this happens to others as well.  A bit more googling, and I found a well written how-to fix it.  The article author stated it could be copied, with a link back to the original source (given at the end).

So here goes … with some small editorial changes ..  the text below assumes that we are working on a LINUX system running CentOS.

How to Repair a Crashed `wp_options` Table

So you are hosting WordPress blog, and there were some server/WordPress updates, or similar disasters that caused your WordPress options tables to crash?

  • You are getting message: Error establishing a database connection ?
  • You don’t have a backup, and hosting staff is incompetent, and asking from you database backup to restore it?
  • You tried PHPMyAdmin to repair tables, but it doesn’t work? You get some dumb ‘blob’ messages from phpmyadmin?
  • You are pulling your hair out?

You don’t think being bald is trendy but here’s the solution:

=========================
Well, this solution is quite simple, but it took the original auther plenty of time to find working solution.

Solution is applied through SSH,and you need to connect as the root user.

You need to stop mysqld service by typing:

# service mysqld stop

then run this command

# myisamchk /var/lib/mysql/YOURDBNAME/*.MYI

Search through output, and find something like this:

MySQL-TableCheck

Then run this command:

# myisamchk -r /var/lib/mysql/YOURDBHERE/wp_options.MYI

MySQL-TableRepair

and last, but not least start mysqld:

# service mysqld start

Then check your site, it should load now.

Original article found here.

And yes, my site came back online.  Now why the wp_options table would “crash” is something for another post.