Wednesday, May 11, 2011

"Error establishing a database connection" from wordpress even when db credentials are correct

Yes i got hit by this just today!!

Let me tell you guys one thing i am not that much into Wordpress for any reason. But one of my blog is on Wordpress and obviously i am not the person who manages it but i do look into technical stuff if it goes out of hand(of my buddy)

Encountered a strange problem where in an existing install of Wordpress(which is about 1 year old) showed a message "Error establishing a database connection" in complete page, all of a sudden. wooohhhh!!!

and then i tried looking out for any changes in wp-config.php(which stores db credentials) but they all were fine. I crossed checked it by manually connecting to the db with credentials provided from console and yes i was able to connect to but Wordpress was telling me that it didn't.

I thought lets take a backup of the existing database and then try to debug it (so that in case i loose some data during this play i am in a position to recover too) but there was something waiting for me.... ufff!!!!

mysqldump -u some_user -psome_password xxxxxxxxx_blog > xxxxxxxxx_blog.dump.sql

and i got this in response
mysqldump: Got error: 145: Table './xxxxxxxxx_blog/xxxxxxxxxblog_options' is marked as crashed and should be repaired when using LOCK TABLES

so due to some activity we have blog's options table all messed up... so what to do!!

Answer is go to /var/lib/mysql/
and run myisamchk on the tables mentioned that should fix it.

something like..
sudo myisamchk -r ./xxxxxxxxx_blog/xxxxxxxxxblog_options

with output:
- recovering (with sort) MyISAM-table './xxxxxxxxx_blog/xxxxxxxxxblog_options'
Data records: 210
- Fixing index 1
- Fixing index 2
Data records: 208

and whola!!! my blog is back :D

Hope this must have helped you in anyway or the other.... will be back soon with more life like post.. these computer tech blogs.. uff uff!!

No comments:

Post a Comment

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...