Unexpected WordPress Database Table Error [WordPress Fix]
Two days ago, out of nowhere, a particular table in the WordPress in hongkiat.com went corrupted. The ‘wp_comments‘ table of the WordPress database just crashed without signs, warnings nor error messages. So how did I came to know? Here are the symptoms:
- If you try to back up your database, you’ll be thrown with this error message – wp_comments is marked as crashed and should be repaired when using LOCK TABLES
- Recent comments widget appears blank.
- Top commenter widget appears blank.
- Comment posted will not be written into DB, therefore will not be shown.
- Comments section in WP Admin appears to have zero records.
After searching the Internet high and low in hoping to find similar cases to help me identify and fix the problem, I end up with nothing. So I tried it my way and luckily enough, I managed to solved it. I thought writing the entry out will not only help those who suffered the same, also keep myself reminded just in case I hit on this error again in the future.
The fix / Solution
To fix this, you must have access to the wordpress database, either via PhpMyAdmin or Secure Shell (SSH). Most shared hosting account comes with phpMyAdmin, but either option you should be extremely careful because you dealing with the database. Any wrong move will cause more data lost.
In PhpMyadmin, select the WordPress database and look for the error table. In my case, the ‘wp_comments‘ table. Check it, and scroll all the way down and look for ‘With selected‘ drop-down box. Select Repair table and things should be alright.
- Login to your shell
- Enter ‘mysql -u username -p database_name‘ to access databases
- Enter ‘show databases;’ to view all databases
- Enter ‘use database_name;‘ to engage the database
- Enter ‘show tables;‘ to show all tables within the database
- Enter ‘check table wordpress_table_name‘ to verify this is the corrupted table
- Fix it with ‘repair table wordpress_table_name‘
- Enter ‘check table wordpress_table_name‘ again to make sure it’s fixed
Step 3 and 5 are not necessary if you are familiar with your databases and tables. Hope this helps.
This post is published by a Hongkiat.com staff (editors, interns, sometimes Hongkiat Lim himself) or a guest contributor.