How to Repair WordPress Database or Optimize Database Tables?


A database is immediately built when loading WordPress on your website. The database is an important part of the website and the database can be accessed from the web server account of the website (more on this later). Think of it like a filing cupboard where comments, posts, name of the blog, user details are kept, essentially all the stuff on the website. Knowledge is stored in the database in a standardized way.

Data from the archive is collected and presented any time a guest attempts to enter the website. Naturally, users would look at an empty website if the link between the database and the website is severed, and most likely never return.

The database is notorious for the periodic collapse of tables. Visitors to the website can see database failures when the database is broken, incomplete or has corrupted tables. They are likely to experience errors generating messages such as “Cannot establish a WordPress database connection” or “Warning: Failed to open stream” etc.

What Happened to the WordPress Database?

That the database is compromised, broken or absent, as these database link error messages occur. And, if any of the following misfortunes have happened, the record could be compromised, broken or otherwise missing:

  • Entering wrong passwords in the file wp-config.php.
  • The host server on the network fails.
  • You’ve hit the PHP memory limit, which triggers server disruption.
  • File permissions are not correctly set up.
  • Blocking the website or at least certain portions of it may be the external firewall program that you are using.
  • Third party WordPress plugins cause content to split or erase file paths.
  • You have been hacked, and your site and MYSQL servers can be reached by others, etc.

Fixing the mistake is, however, probable. By refining the index, all these misfortunes can be minimally avoided.

But it is recommended that you back up your WordPress database before you begin the repair process. You would end up missing the content of your website without the WordPress backups should anything happen to your website. With a copy, you would have the confidence to make database adjustments. You can easily recover the backup if anything goes wrong, and the website will be up and running within minutes.

You can restore or even download the database in a couple of steps and store it in your system. But you’ll need to take a few more precautions if you want to import either a single file or data.

Backup WordPress Database:

Step 1: You’ll need to access your web host account. Choose phpMyAdmin. When the phpMyAdmin page opens, you can see the database tables. All WordPress databases have 12 tables by default. As your website grows and you, more and more tables are created.

The default tables are as follows –
1: wp_commentmeta
2: wp_comments
3: wp_links
4: wp_options
5: wp_postmeta
6: wp_posts
7: wp_terms
8: wp_termmeta
9: wp_term_relationships
10: wp_term_taxonomy
11: wp_usermeta
12: wp_users

Step 2: On the page, you should be able to see a tab called Export on the top of the screen. Click on it, and it’ll reveal two options:

  • Quick – Display only the minimal options
  • Custom – Display all possible options

You’ll end up exporting the whole database if you want Fast.

But if you pick Tradition, you can kick in a few more choices. You may choose a particular table or tables to export from a drop-down menu.

Step 3: Next, you need to pick the backup format. You should go with the SQL default option or any other format you think is convenient for you. Click on GO after you have picked the format.

It will take a few minutes before the whole backup is transferred to your device, depending on the size of the whole database or the particular file.

Now that you have your database backup safe and within your control, here’s how you can restore the database and customize it. Two ways to do this are open. Now, WordPress (version 2.9 and above) comes with a recovery feature for the database. The features are designed for individuals lacking technological experience or awareness, allowing users to patch compromised files and databases in only a few steps. You should give phpMyAdmin a try if this doesn’t work. In all these ways, we will direct you.

WordPress Database Repair Using WP ALLOW REPAIR:

Your web server account would need to be accessed. From the alternative available on the left side of the screen, go to File Manager and click public html. Check now for wp-config.php. Right-click and pick Edit in the wpconfig format.

Attach the following line into the text-editor:

define( 'WP_ALLOW_REPAIR', true );

Make sure you are inserting this line above the "if ( !defined('ABSPATH') )" line.

Save the modifications now. If you know what you are doing, do not make any further improvements to the website.

After saving, open this URL:
(Make sure to overwrite *yoursite* with your WordPress blog’s actual name) Note that to view this page, you must be logged in.

You should see a WordPress page with two buttons upon opening the website that say:

  • Repair Database
  • Repair and Optimize Database

You can press any button, and the corrupted database will be fixed. But since it also optimizes the database, we suggest using the second choice to restore the WordPress database.

You can see the following message on the screen after WordPress fixes the website.

The only thing left to do now is to delete the “define(‘WP ALLOW REPAIR ‘, true);” line that you added to the config file.

If you fail to follow this process, the WordPress database table can be restored and optimized in another way.

Repairing MySQL Database Tables

  1. You would need to enter the account of your web host and then pick phpMyAdmin. You should be able to imagine the table in the database on the phpMyAdmin website.
  2. There will be a box on the left side of each of the desks. For the tables you need to patch, search the boxes.
  3. An choice named With Selected should be in place. A drop-down menu will appear if you select that one.
  4. Pick Table Repair from the drop-down menu.

The tables are repaired immediately. And then a page with the fix result will appear.

Optimizing MySQL Database Tables

  1. There will be a box on the left side of each of the desks. For the tables you need to optimize, check the boxes.
  2. An choice named With Selected should be in place. A drop-down menu will appear if you select that one.
  3. Pick Optimize the Table from the drop-down menu.

The tables are repaired immediately. And then a page with the fix result will appear.


The problem with database links is not unusual. And there’s no assurance when you patch the issue that it won’t happen again. While certain database problems (like when the web host crashes) are beyond your influence, other problems can be avoided (like protecting WordPress websites from hackers by using a WordPress website security services). In addition, a few other security steps can also be taken, such as switching the website from HTTP to HTTPS, hardening the website, securing the login tab, etc.

We hope you find the guide useful and were able to patch infected database files and get them running again and restore WordPress pages.