How to Repair a Corrupted Database
There are a couple of ways you can repair a corrupted database. If you see a “Cannot establish database connection error”, then one solution that works for most issues is as follows.
Follow these steps to repair a corrupted database via the Database Repair Page:
1. Log in to your control panel, access File Manager, and navigate to your WordPress installation (most commonly under public_html).
2. Open your wp-config.php file, then add this line at the root of your install:
define( ‘WP_ALLOW_REPAIR’, true );
Add it anywhere in your file but not in the middle of a function. We recommend placing it at the very end of your file so that it is easy to find, as you will need to remove it once you have repaired your database.
3. Once you have added the above line, you can visit the Database Repair Page: your-site.com/wp-admin/maint/repair.php. Make sure to replace your-site.com with your actual domain name.
You don’t need to log in to view this page. Therefore, you must remove the line mentioned earlier when you finish repairing your corrupted database. If you don’t remove it, anyone can access that page.
4. When you visit the link, click the Repair Database button, or optimise your database whilst you repair it by clicking the Repair and Optimize Database button.
5. Once the process is complete, your site should be fixed and ready to go.
If that doesn’t work, you can repair your database through phpMyAdmin.
Follow these steps to repair your corrupted database via phpMyAdmin:
1. After logging in, click on your database on the list to the left. When your database tables load, scroll down and click the Check All box. Lastly, in the drop-down box next to the check box, select Repair table.
2. Your corrupted database tables will automatically repair, and your site should be functional again.
For another solution to fix a database connection error for WordPress, follow the steps in our blog: dreamithost.com.au/how-to-fix-a-database-connection-error-for-wordpress.