Error establishing a database connection - Wordpress Error

Well, for the last few weeks I ve been seeing this error quite often on my blog. I didn't think of it much initially as it used to go away on a mysql restart. However, today I ran into it and was persistent after mysql restarts. So I started digging a bit more and enabled debugging in wp-config


in wp-config.php

define('WP_DEBUG', true);
define('WP_DEBUG_DISPLAY', true);

This didn't show any error that could help me. I could ve tried enabling further logging in apache to see if that helps

http://codex.wordpress.org/Editing_wp-config.php#Configure_Error_Log

I had tried logging into mysql with the username and password configured in the wordpress config and it worked fine. So I knew those were fine and mysql was running fine. I even restarted httpd a few times to confirm, but it didnt help either.

Then I checked up the mysqld log and voila!

 

101:130113 10:15:33 InnoDB: Database was not shut down normally!
116:130113 16:37:34 InnoDB: Database was not shut down normally!
131:130113 16:39:16 InnoDB: Database was not shut down normally!
146:130113 16:42:20 InnoDB: Database was not shut down normally!
158:130113 16:45:05 InnoDB: Database was not shut down normally!

130113 10:15:32 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130113 10:15:33 InnoDB: Initializing buffer pool, size = 8.0M
130113 10:15:33 InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130113 10:15:33 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
130113 10:15:33 InnoDB: Started; log sequence number 0 1049991
130113 10:15:33 [Note] Event Scheduler: Loaded 0 events
130113 10:15:33 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.56' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
130113 16:37:04 mysqld_safe Number of processes running now: 0
130113 16:37:04 mysqld_safe mysqld restarted
130113 16:37:29 InnoDB: Initializing buffer pool, size = 8.0M
130113 16:37:30 InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130113 16:37:34 InnoDB: Database was not shut down normally!

Version: '5.1.56' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
130124 20:22:26 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:22:26 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:25:00 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:25:00 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:33:04 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:33:05 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:33:05 [ERROR] /usr/libexec/mysqld: Incorrect key file for table './wp_options.MYI'; try to repair it
130124 20:34:44 mysqld_safe Number of processes running now: 0
130124 20:34:44 mysqld_safe mysqld restarted
130124 20:34:47 InnoDB: Initializing buffer pool, size = 8.0M
130124 20:34:47 InnoDB: Completed initialization of buffer pool
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
130124 20:34:48 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
130124 20:34:48 InnoDB: Started; log sequence number 0 1049991
130124 20:34:48 [Note] Event Scheduler: Loaded 0 events
130124 20:34:48 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.1.56' socket: '/var/lib/mysql/mysql.sock' port: 3306 Source distribution
130124 20:34:59 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:34:59 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:34:59 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:34:59 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:34:59 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:34:59 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:35:06 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired
130124 20:35:06 [ERROR] /usr/libexec/mysqld: Table './wp_options' is marked as crashed and should be repaired

So looks like this is what was causing my recent problems.

Once I saw this in the mysql logs, it was a simple fix:


mysql> repair table wp_options;

Found 231 of 230 rows when repairing wp_options

 

And so far its all been good after that :)

Written on January 26, 2013