#Howto repair a crashed #WordPress #database table


A WordPress database may experience failure and corruption under various circumstances. One of common problems with it is "crashed database." When that happens, you will find the following error in WordPress error log:
WordPress database error Table './my_home/wp_posts' is marked as crashed and last (automatic?) repair failed for query SELECT post_date_gmt FROM wp_posts WHERE post_status = 'publish' AND post_type IN ('post', 'page', 'attachment') ORDER BY post_date_gmt DESC LIMIT 1 made by require('wp-blog-header.php'), wp, WP->main, WP->send_headers, get_lastpostmodified, get_lastpostdate, _get_last_post_time
The symptom of such table crash varies. Depending on which table was crashed, your WordPress blog may malfunction differently. If a crashed table is 'wp_posts' table which contains a list of posts, you will not see any post in your blog.

Why a MySQL Table Crash?

There may be different reasons, but typically when mysqld or the host where mysqld is running is forcibly shut down in the middle of a database update, a database crash can be triggered. In the rest of the tutorial, I will showhow to repair a crashed WordPress MySQL database table.

Method One

If you are using a shared web hosting, typically you will have access to Cpanel, which allows you to repair a database through Cpanel web interface.
Log in to Cpanel, and click into "MySQL Databases" under "Databases" section.
On MySQL Databases" page, you will find "Repair DB" option under "Modify Databases" section.
Choose the database which contains a crashed table, and click "Repair DB" button. If repair is successful, you will see the status of every table as "OK".
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my_database.wp_oiopub_tracker_visits OK
my_database.wp_options OK
my_database.wp_postmeta OK
my_database.wp_posts
error : Keyblock size at page 13001728 is not correct. Block length: 532 key length: 2
Error : Incorrect key file for table './my_database/wp_posts.MYI'; try to repair it
error : Corrupt
---------
After repair:
----
my_database.wp_oiopub_tracker_visits OK
my_database.wp_options OK
my_database.wp_postmeta OK
my_database.wp_posts OK
my_database.wp_sharebar OK
my_database.wp_term_relationships OK

Method Two

If you have root access on the host (e.g., VPS) where a MySQL sever is running, you can try command-line interface to fix the crashed database table.
For a MyISAM-type database, you can fix a crashed table with a command-line utility called myisamchk. This utility comes with MySQL server installation.
First, stop MySQL server.
$ sudo service mysql stop (Debian/Ubuntu)
$ sudo service mysqld stop (CentOS/RHEL)
$ sudo systemctl stop mysqld.service (Fedora)
Then use this command to fix a particular table.
$ cd /var/lib/
$ sudo myisamchk -r -v -f mysql//
Finally, start MySQL server again.


One Response so far.

  1. Blogger says:

    Bluehost is ultimately the best web-hosting provider with plans for any hosting requirments.