How to repair wordpress database

If your website have insufficient ram, your website’s database may crash ( error establishing a database connection error ) or database table not closing properly.

1. Repair wordpress database using /wp-admin/maint/repair.php

We strongly recommend check, repair and optimize your WordPress database at least once a week to ensure your website can perform at full speed. This article, we will show you 5 methods to repair WordPress database.

1. Repair wordpress database using /wp-admin/maint/repair.php

Many people may not aware of this awesome database repair function exist. You can repair your database with just 3 simple steps

1. Simply type /wp-admin/maint/repair.php at the end of your domain, you will see this.

wp-admin repair

2. Copy and paste this code into your wp-config.php. You can use ftp client such as filezilla to do this or use the file manager in cpanel.

define('WP_ALLOW_REPAIR', true);

3. Then, you will see this screen. The last step is to click the repair database button. You can also click the repair and optimize database button. Your WordPress will be on repair mode and WordPress CMS will do the repair job really well. A note: If your website have WooCommerce and have thousands of products, we recommend try to repair database first.

wordpress database repair

2. Repair wordpress database using cpanel

Type /cpanel or /2083 at the end of your domain name. You will be redirect to cpanel login page. You can also use your hosting client area to login.

After login, search for MySQL® Databases. Then you will see something like this. Choose your database, click the repair database button and you are all set.

Repair wordpress database using cpanel

3. Repair wordpress database using phpMyAdmin

Login into your cpanel > phpMyAdmin

Cpanel system will redirect you. If you only have one website hosted in your hosting account ( no matter shared, cloud or semi-dedicated ), you will only see one database on left. If you host multiple websites, you will see multiple database.

Choose your database and the database table structure will show. Click check all.

The with selected dropdown, choose repair table.

4. Repair wordpress database using SSH command

Run the below command if you want to check your database for errors. Replace XXX with your database name.

mysqlcheck XXX 

Run the below command if you want to auto repair your database.

mysqlcheck --auto-repair XXX

Run the below command if you want to repair your database.

mysqlcheck -r XXX

5. Repair wordpress database using plugin

You can repair or optimize your wordpress website database using free plugins. Off course, some people may prefer WP Cleaner Pro ( $19 ) because WP Cleaner Pro can also create the database backup, restore the database in WordPress dashboard without login to cpanel. So overall, if you prefer one plugin to do 3 tasks ( backup database, restore database, optimize database ), WP Cleaner Pro is the plugin to choose.

Let’s proceed with the free plugins.

1. LiteSpeed Cache

Click on litespeed cache > Database. Then click clean all. If you want to keep auto drafts or trashed posts, you can manually tick on what you want to optimize.

LiteSpeed Cache Database Optimization

The DB optimization settings tab, you will the revisions max age. If you want to keep all revisions newer than 1 days, set it to 1. Then go back to manage tab and click clean all.

Draft and revisions is different. Draft is those post that you manually save as draft while revisions is the auto save build in function of WordPress. WordPress will auto save your the post, page or any custom post types you actively working on every 60 seconds. Pretty cool right? Actually not. We should turn off WordPress revision to save server resources.

2. Advanced Database Cleaner

This is a plugin specially created to repair and optimize WordPress database. It support Wp multisite, will show you script max time out, how many tables to optimize, total unused data, database size, table size and the best part is – this plugin allow you to schedule database optimization per table basis for free.

Advanced DB Cleaner

3. WP-Optimize

WP-Optimize allow us to optimize database tables, clean all post revisions, clean auto-draft, clean trashed posts, remove expired transient and clean orphaned relationship data.

Please keep a good practice. Always backup your database first before you proceed with any database repair or optimization task. Sometimes, the data might corrupted after optimization operation.