When it comes to CMS (Content Management Systems) like WordPress, database is one of the most important component. This database stores all your posts, pages, and also your settings which makes it very important. Everything that you do is written in the database but sometimes this database can also get corrupted due to some reason and if that happens, then your website will start to malfunction. In this short guide, you will learn how to repair a crashed WordPress database, and get your website working again.
So why does this problem happen in the first place? This WordPress posts table can get corrupted due to any unexpected event, or any technical reason in the server. This causes website to malfunction, and you will find that all your data from Posts and Pages are gone. However, there’s no need to worry as your data is still there, and this problem happened because of a crashed posts table in the database. Because of this, you might also see 404 errors on existing pages where there was content before. So if you are facing such strange issues, then don’t worry, just follow the below instructions and you will be up and running in no time.
Fixing a crashed WordPress database table
Now, there are two ways to do this. You can opt for any one of these methods to solve your problem.
Method 1: Editing WP-Config.php File
This method is really simple, and easy. In fact, WordPress itself recommends users to use this method to repair a corrupted database, regardless of whether you are able to login to WordPress or not.
In this method, all you need to do is to just add the following line to your wp-config.php:
define( ‘WP_ALLOW_REPAIR’, true );
After doing this, you need to visit your site from this URL at: http://yoursite.com/wp-admin/maint/repair.php. Here, replace yoursite.com with your actual website’s URL.
Here’s how you can edit this file if you are new to this. You can use a FTP client like Filezilla, navigate to the root of your WordPress installation, download this file, edit it and then upload it again. Or you can also directly login to your web hosting control panel (also known as cPanel), launch File Manager from there, and then edit the file.
Note that you should not change anything else from there, unless you know what you are doing.
Method 2: Using phpMyAdmin
If you are comfortable using phpMyAdmin, then you will like this method. This method too, does the same thing as the above method.
Login to your web hosting control panel (or cPanel), and click on phpMyAdmin from the Database section. From there, select your database that you want to edit from the left side.
Now, look for wp_posts table, select it and then from the drop-down, click on “Repair table”. phpMyAdmin will now repair your selected table and hopefully your problem would be solved. (Note that if you have changed your database prefix, then you would find something else instead of “wp”, but the “_posts” part will remain the same. For example, you might be able to find “xx_posts”, where “xx” is your database prefix).
If you think that some other table is corrupted, then you can select that particular table or you can also select all tables and repair them all.
We would always recommend users to take their complete WordPress backup regularly, along with database backup, so that just in case anything goes wrong, you can just restore it.
So go ahead, repair your WordPress database using this method. Let me know if you face any problem following this method in the comments below.
Bonus Tip: You can also optimize your WordPress database so that your website keeps on performing smoothly.