Your WordPress database contains all of your site's information - so naturally, if it goes down, it is a very stressful experience.
And unless you have a working WordPress backup to restore from, fixing the error as soon as possible is very important. Until you do, your site will be dropping search rankings and losing valuable traffic.
Fortunately, there is an easy way to fix a WordPress database and get everything going again.
In this article, I'll explain to you how to repair your database using WordPress's inbuilt repair function. I'll also explore some of the possible reasons your database got corrupted in the first place.
But now, I'll walk you through 6 simple steps to manually repair WordPress database:
Step 1: Backup your WordPress database
Step 2: From your control panel, start phpMyAdmin
Step 3: Open your WordPress database
Step 4: Select all of the tables in your database for repair
Step 5: Start the WordPress repair process
Step 6: Verify that the repair was successful
1. Backup Your WordPress Database
Important note: Before attempting to repair your WordPress database, you should back it up.
This can be done easily using a large number of WordPress plug-ins. However, given that you probably can't access your WordPress account directly, our article on creating a manual WordPress database backup is a good place to start.
Remember, just because your WordPress database is corrupted, it doesn't mean all your data is irretrievable.
Restoring your data is possible, so it's worth having a go and protecting the data you already have.
2. From Your Control Panel, Start phpMyAdmin
Next, open your WordPress server's control panel from your hosting account.
You'll probably need to log in with the password and username you set when you created your hosting account. If you've forgotten your credentials, open a support ticket with your hosting provider to reset your password.
Once you're logged in, you'll be presented with a panel that looks something like the screenshot below.
Next, you'll need to find and click on the phpMyAdmin button.
If your control panel looks different, don't be concerned.
Most hosting providers use cPanel (shown here), but if your host provides another cPanel alternative or management software, that won't be a problem. No matter what control panel you have, phpMyAdmin will probably be located under a 'Databases' header.
phpMyAdmin is a Linux based database manager. It's the program most web hosts use to manage WordPress databases.
If you've never used Linux or have no code experience, don't panic. Everything's under control - you won't need any previous technical knowledge to complete this guide.
3. Open Your WordPress Database
Now that you've entered the phpMyAdmin interface, you need to select the correct WordPress database.
For most servers, this will be an extremely simple step. However, if you host more than one WordPress site from the same server, things will be less straightforward.
Look at the section on the left side of your screen. That's a list of the various databases installed on your server.
The names might look a little strange, but that's normal. Your WordPress database's name will probably contain a mix of random letters and numbers, but you'll be able to identify it as it will contain a '_wp_' for WordPress.
Once you identify the WordPress database, select it by clicking on it.
Your internal database folders will then appear in the sidebar. This will allow you to double-check that you've selected the correct database: the folder names should all begin with 'wp_'.
Note: if you have multiple WordPress sites on your server, there'll be more than one WordPress database.
As the database naming system is random, you'll need to expand the 'wp_posts' table and check that the names of the posts match those of the corrupted site.
4. Select All of the Tables in Your Database for Repair
Once you've opened the correct WordPress database, you need to ensure that every part of it is repaired (unless your error message told you that only one part of your database was corrupted).
To do that, go to the bottom of the main directory window and select the 'Check all' box. This will highlight all the subdirectories within your WordPress database.
5. Start the WordPress Repair Process
Once every subdirectory is selected, open the list next to the 'Check all' field and select 'Repair table'.
Congratulations, you've now managed to start the repair WordPress database process!
But wait, before open champagne and try to log in to WordPress again, you still need to check that the repair worked.
6. Verify that the Repair Worked
You'll now be taken to the repair results screen. The messages displayed here will tell you if the repair was successful. Along the top, you should see the following message:
However, even if that text appears, you still need to check the rest of the output window.
A note such as 'The storage engine for the table doesn't support repair' means the database error wasn't fixed, and it's time to try an alternative method.
Alternative Solution: Modify your wp-config.php File
The second straightforward to fix WordPress database is to modify your WordPress configuration file in order to access WordPress's built-in repair function. To modify your wp.config.php file, follow these steps:
- Return to your control panel and open your servers' FTP client
- Download the file named 'wp-config.php'
- Open the downloaded file in a text editor
- Just before the if
( !defined('ABSPATH') )line, insert this text:
- Save the 'wp-config.php' file
- Upload the modified 'wp-config.php' file to your FTP server, overwriting the previous version
- Navigate to http://sitenamegoeshere.com/wp-admin/maint/repair.php, replacing 'sitenamegoeshere.com' with your site's URL
- Click 'Repair Database'
- Replace the 'wp-config.php' file with the original, unmodified version
If you managed to follow the first six instructions correctly, at step number seven you'll arrive at this screen:
If such a page doesn't load for you, verify that you managed to modify your .php file correctly and that you replaced it in the correct folder (normally your server's root directory). The bottom of your modified .php file should look exactly like this when you open it in your text editor:
One More Way To Repair WordPress Database
This one does not require any technical knowledge.
If you happen to host your website with one of the WordPress hosting providers that specialize in specifically in WordPress, the only thing that you might need to do is contact the support team.
Some of the best WordPress hosting providers have teams of the CMS experts. So they'll be able not only to diagnose your problem but to fix it as well.
Or at least they will guide you through the process via phone or live chat.
What Corrupted Your Database?
Once you've repaired your database, it's important to determine how it got corrupted in the first place. You know, so it doesn't happen again.
These are some of the common ways your database might have been damaged:
- Software incompatibility issues: If the PHP or MySQL version on your server is outdated, WordPress might not be able to load properly.
- Plug-in failure: A misbehaving WordPress plug-in can easily bring your entire site down. Try toggling recently installed plug-ins to identify the culprit.
- Incorrectly set file permissions: If WordPress isn't allowed to read certain important files on your server, it won't be able to startup correctly.
- Hardware failure: A machine malfunction in your host's data center could damage vital WordPress files. If you find that's happening regularly, it's probably time to change host!
I recommend you use the list above to troubleshoot your WordPress site and establish how it became corrupted, If you don't, you won't be able to prevent it from happening again!