How to Fix Corrupted Files and Databases in WordPress

Posted on December 12, 2017 by in Tips & Tricks | 32 comments

How to Fix Corrupted Files and Databases in WordPress

WordPress is a fantastic platform that offers rock solid stability 99% of the time. However, errors are an inevitability that no platform can outrun. In most cases, they’re easy to fix. However, corrupted files fall into a tricky category, since it can be challenging to narrow down their cause.

Fortunately, there are plenty of ways you can deal with WordPress corruption issues even if you’re not 100% sure why they’re happening. In this article, we’re going to talk about some of the most common culprits behind corrupted files in WordPress, then we’ll teach you how to fix them using three different methods.

Let’s do this!

What File Corruption Is (And How It Happens Within WordPress)

An example of a database related error.

Corrupted databases can lead to connection errors.

When you can’t access files that used to be fine, that’s corruption. With regard to WordPress, you may not be able to access some of its core files, establish a connection with your database, and more. There are a lot of factors that can lead to file corruption, but these are some of the top culprits for WordPress websites:

  • Server failure. If your server goes down while WordPress is updating a file, it can become corrupted since it won’t save the changes correctly.
  • Incorrect file permissions. In some cases, improper file permissions can lead to the malfunction of WordPress files.
  • Errors with your version of PHP or your database software. Sometimes, an update to your server’s software can cause compatibility errors that lead to corruption in WordPress’ files and its database.

It’s important to note that WordPress doesn’t explicitly tell you when some of its files become corrupted. In most cases, the corruption will lead to a broad variety of errors, each with their own message. For example, if your database becomes corrupted, you may not be able to even establish a connection. It may also be that WordPress can no longer locate one of its core files, which can render your installation unusable.

With that in mind, if you run into a WordPress error for which you can’t find a specific fix, chances are it’s related to file corruption. If that’s the case, here are the steps you should follow.

How to Fix Corrupted Files and Databases in WordPress (3 Ways)

There are three ways to tackle corrupted files in WordPress. For the best results, you’ll want to approach these solutions in the order they appear. Plus, you’ll need to use a File Transfer Protocol (FTP) client for all three methods. We recommend FileZilla, but you’re free to use whatever program you’re comfortable with.

1. Restore Your Website From a Backup

Restoring a website.

Restoring a recent backup is the easiest way to fix plenty of errors.

Backups can solve basically any problem you have with your website. Ideally, you’ll back up your site often, so you can simply restore it to an earlier version if anything goes wrong, without losing too much content.

In other words, doing a full restore (of your files and database) is the perfect way to reverse corruption on your installation. If you have a backup plugin, such as UpdraftPlus, you should be able to restore your website from your dashboard using our previous guide on the subject.

On the other hand, if you can’t access your dashboard, things get a bit more complicated – although they’re still solvable. Depending on your web host, you may have access to automatic backups or a server restore feature that’ll enable you to roll back things to an earlier state. For example, Flywheel sets up automatic daily backups for you, letting you to restore them with a couple of clicks:

Flywheel restore feature.

If your host doesn’t provide this option and you can’t access your dashboard, you’ll have to restore your site manually. As long as you have a recent backup file saved locally or to cloud storage, you can restore it within a handful of steps (otherwise, proceed to the second method). The backup should contain a database file, your plugins, themes, uploads, and other files. To restore your database, you’ll need to access the phpMyAdmin tool within cPanel. Once you’re in, locate your WordPress database, select all of its tables and use the Drop option to delete them:

Dropping your database tables.

Now that you have a clean slate, go to the Import tab within that same database and look for the Choose File button:

Importing a database.

Find your database backup file, which should be in the .sql format, and select it. Now click on the Go button at the bottom of the Import tab. The process should only take a few seconds, and once it’s complete you’ll see a success message. If you go back to the Structure tab, you should see that it’s no longer empty:

phpMyAdmin's structure tab.

The final step is to restore your WordPress files. Access your server using your FTP client and head to WordPress’ root directory. In most cases, it’s called public_html, but it also may be under www or named after your website:

WordPress' root folder.

Open that folder, select all the files inside, then right-click and delete them. Next, stay within the folder while you re-download WordPress’ core files from its official website. Most backups only include your theme, plugin, and upload folders, so you’ll need to ‘set up’ the rest of WordPress separately. When the download is complete, unzip the file, return to your FTP client, and access the local wordpress folder:

The local WordPress folder.

Select all of those files, then right click and upload them. If you’ve followed our instructions and kept your FTP client open, they’ll go right where your old WordPress setup used to be. This process can take a while, since there are a lot of files. When that’s done, go to wp-content/plugins and upload all of the plugin folders within your backup file:

Your plugins backup folder.

This process is simple – just select all the folders you want to restore and click on the Upload option within your FTP client. Then repeat the process for your themes (which go into wp-content/themes) and uploads (located in wp-content/uploads). After you finish all three rounds of uploads, you should be able to access your site again without errors. If you went through all this process from an old backup, remember to schedule regular ones in case it happens again!

2. Repair the WordPress Database

A list of databases.

Your database can also get corrupted, which can break your WordPress site.

If backups are out of the question (because you don’t have any recent ones), you should first look to repair your database. WordPress includes a built-in feature that enables you to do this, but it’s turned off by default.

To activate it, return to your FTP client and go to the WordPress root directory. Inside, you’ll find a file called wp-config.php. Right-click it and look for the View/Edit option. This will open the file locally using your default text editor:

Opening your wp-config file.

Once you’re in, look for the line reading That’s all, stop editing! Happy blogging. This comment signals the end of the file, and you paste the following line right above it:

define( 'WP_ALLOW_REPAIR', true );

Technically, you can add that line anywhere in the file you want. However, it’s best to place it right at the end, so you can be sure it doesn’t interfere with the rest of the file’s code. Once you’ve enabled WordPress’ database repair function, you can access it by navigating to http://yourwebsite.com/wp-admin/maint/repair.php.

A new screen including two options will pop up – click on Repair Database:

Using wp_allow_repair to repair your WordPress database.

Now, wait for WordPress to work its magic. When the repair is done, you should be able to access your site without any errors. However, if your site is still facing problems, it’s time to try out method number three.

3. Replace WordPress’ Core Files

Some of WordPress' core files.

WordPress core files are critical to your website’s functionality.

If you couldn’t restore your website from a backup or repair your database, you’ll simply need to replace all of your WordPress core files. This process is rather straightforward, but it will cause you to lose any customizations you’ve made to any of those files.

To do this, download the latest version of WordPress from the platform’s home page and unzip it. Now open both your FTP client and the WordPress folder you just decompressed as your local directory:

Your WordPress local directory.

Keep that folder open for now while you access your site via FTP on the other side of the screen. Next, navigate to WordPress’ root folder, select all the files in your local wordpress directory, and upload them:

WordPress' root folder.

At this stage, your FTP client will ask you if you want to overwrite any duplicate files on your server. Choose “Yes” for all files, and sit back while everything uploads. This process should only overwrite your WordPress core files, and it won’t affect any plugins or themes you’ve downloaded. In fact, you can use this same process if you ever run into a situation where you need to update WordPress manually.

When everything’s done, go ahead and try to access your site once more – it should now be working perfectly!

Conclusion

Troubleshooting WordPress can seem intimidating, but in most cases, it’s rather simple. Once you identify what’s wrong with your site, you’ll likely find dozens of guides on how to deal with it. Corrupted file errors are a bit more complicated, since they can have many causes. However, you can still make short work of them if you investigate the problem methodically.

Here are the three best ways to fix corrupted files in WordPress, and the order in which you should approach them:

  1. Restore your website from a backup.
  2. Repair your database.
  3. Replace your WordPress core files.

Any questions? Let’s talk troubleshooting in the comments section below!

Article thumbnail image by I000_pixels / shutterstock.com.

32 Comments

  1. Thanks John for the information, it is very clear and helpful.

    • John Hughes

      No problem, Clara. Glad you found it useful 🙂

  2. The problem I’m having, which no one seems to be able to answer is, I can’t get into my WordPress dashboard even though I’ve changed my password and email recovery in Hostgators PHP My Admin / WP-users. I keep getting a ‘too many login attempts’ message, and Hostgator is pretty much useless in the help department..

    • Hi Stephen,

      Are you using some form of security plugin? If you are you could try deleting the directory, I would also check the contents of your .htaccess file (if you’re using one) and make sure that only the most basic information is there – https://codex.wordpress.org/htaccess will show you exactly what’s needed.

      Let me know if that works.

      Adam

  3. Thanks. Does anyone know if this “repair database” option does exactly the same as the phpMyAdmin function? I’ve got a misbehaving woocommerce installation and nothing I’ve done via phpMyAdmin has fixed it.

    • John Hughes

      Hi Mark. Sorry to read that you’re having problems. If you’ve followed the advice in the article and are still experiencing difficulties, you may have a Divi issue. By getting in touch with us, we can ascertain your best course of action.

  4. Awesome sharing. Thanks

    • John Hughes

      No problem, James. 🙂

  5. Just what I was looking for, boy do I have problems and now I can repair them.

    • John Hughes

      Hi Laurie. Glad you found the article helpful.

  6. Learn this if you have the interest or spare time, otherwise, just get your WordPress website host to fix corruption problems. I recently had a database corruption issue. I just wrote a support ticket and my host fixed the problem. Good hosts also back up your site(s)regularly, which mine does and has saved me a few times when I have made changes that crash a site, but I use a backup plugin just in case.

    • Are you at liberty to mention the hosting company.

    • John Hughes

      Hi Eric. It’s always a good idea to have a backup plugin in place. We also strongly recommend sending support tickets in the event of unforeseen issues. However, in many cases, learning how to fix corrupted files can be useful in the event that a quick response is not forthcoming. Thanks for your comment.

  7. We have also been facing difficulties with importing Divi Layouts, so it’s very possible that we need to configure something with the WordPress. Please help us by writing an article on the issue!

    • John Hughes

      Hi Bkmillanzi. Thanks for the suggestion. We will bear this in mind. 🙂

  8. Very useful, will be using this on an old site of mine. Thanks for posting.

    • John Hughes

      No problem, Rob. Glad to help 🙂

  9. Hi! I’m a little perplexed. In option 3, won’t uploading a fresh “wp-content” folder override any themes or plugins I have in the existing wp-content folder?

    • John Hughes

      Hi Ariana. It will, unfortunately, yes. This step is more of last resort rather than solid fix, and will hopefully only need to be used on rare occasions.

  10. Thanks for the extra insight on DB repair.

    I have been a UpDraftPlus backup user for quite a while and it has saved me a lot of time.

    My standard practice is to store the backup files off server in Dropbox, Google Drive, or OneDrive. This way I can always access the files and do an FTP if needed.

    • John Hughes

      No problem Jeff 🙂 Thanks for the comment.

  11. Thanks for the concise but effective guide.

    • John Hughes

      You’re welcome David 🙂

  12. Very Useful Thanks!

    • John Hughes

      You’re welcome Bryan.

  13. Well that’s an excellent guide for the newbies having large websites. Better to buy out the jetpack backup service that is easy to use.

    • What is the jetbackup and is it free. How does it solve my problem, which I thought was a fairly simple one.

      Is there way I can just paste in the correct file or just the part that’s missing?

      • John Hughes

        Hello Christopher.

        You can find more information on Jetpack and its functions via the following link:

        https://en-gb.wordpress.org/plugins/jetpack/

        The basic version of Jetpack is free. However, there are also premium versions with additional features.

        If you have followed the steps in the article and are still encountering issues, we recommend contacting your host for further assistance.

  14. Is there a way I can paste in the correct file in my website, or even the missing part?

  15. Option nr 3 worked for me, thank you so much for this useful post! I managed to revive a forgotten travel blog.

    • John Hughes

      You’re very welcome Constance. Happy blogging 🙂

500,591 Customers Are Already Building Amazing Websites With Divi. Join The Most Empowered WordPress Community On The Web

We offer a 30 Day Money Back Guarantee, so joining is Risk-Free!

Sign Up Today

Pin It on Pinterest