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. Xmodulo experienced such database crash over the weekend:
The WordPress blog of Xmodulo is powered by MySQL at the moment, so in this tutorial, I will focus on MySQL.
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 show how to repair a crashed WordPress MySQL database table.
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".
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
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.
First, stop MySQL server.
$ sudo service mysqld stop (CentOS/RHEL)
$ sudo systemctl stop mysqld.service (Fedora)
Then use this command to fix a particular table.
$ sudo myisamchk -r -v -f mysql/<database_name>/<table_name>
Finally, start MySQL server again.
Do you have any experience with a crashed database, or any other problem with a WordPress database? Do you regularly back up your WordPress database? Tell us what was your approach to fix the problem and maintain the database.
Subscribe to Xmodulo
Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.