Database Repair

The Database Repair tool compares a corrupt database with a target database, and updates the
target so it has the same structure as the corrupt database. During the process, Database
Repair does the following:

  • Adds missing tables, or repairs them so they have the same engine type and charset
  • Adds missing fields or repairs them
  • Removes inconsistent data from tables with broken foreign key references
  • Adds missing foreign keys and indexes

A typical use case for this tool is to fix the database of an existing Magento installation that
has some of the errors mentioned above. To learn more, see: Magento 1.x Database Repair Tool

Important! Do not use DB Repair on a production site without testing it first in a development
environment. Always back up the original database before using DB Repair.

Step 1: Restrict Access to Website

It is highly recommended that you restrict access to your website while repairing the database.
The following example restricts your Magento instance to your IP address exclusively. Other
visitors, including search spiders, will get the HTTP “503 Service Unavailable” error.

Step 2: Create a Rewrite Rule

1. Create a file called 503.php in your Magento installation root that contains the following
Step 3. Install the DB Repair Tool

1. Download the archived Magento Database Repair tool from the Magento Community Edition
download page.

2. Do either of the following:

  • Upload the archived file to your server, and extract it to any folder.
  • Extract the archive. Then, upload the file, magento-db-repair-tool-1.2.php to any
    folder on your server.

Step 4: Back Up and Clone Your Database

1. Back up your existing database that has the problem, so it can be restored in the event of a
problem. We’ll call it “database1.”
2. Clone “database1” as the new “database2” on the same server.
3. Create a new empty database, “database3.”
4. Do one of the following:

  • Copy the entire Magento folder (without the cache and sessions) to a new location, and
    install “database3.” Then, update the local.xml file with the database credentials.
  • Since access to the site is restricted, you can update the database credentials to “database3”
    for the current Magento instance. Then, clean the cache and launch Magento. The new
    database will be installed automatically.

You now have “database2,” which is a clone of your original database, and a Magento
installation with the empty “database3.”

Step 5: Run DB Repair

1. Enter the following in the address bar of your browser to launch the DB Repair tool:
2. Under Corrupted Database Connection, complete the following information for “database2:”
This information is the same as what is entered during the Configuration step of the Magento
a. In the Host field, enter the server’s fully qualified host name or IP address. If your
database server is on the same host as your web server, enter “localhost.”
b. Enter the following credentials for the MySQL database that has the problem:

  • Database Name
  • User Name
  • User Password

c. If there are multiple instances of Magento that share the same database, enter the Table
3. Under Reference Database Connection, enter the database credentials for the empty
If using a Table Prefix, make sure that it is the same as the the prefix used for Database1.
4. Click Continue to diagnose the database and display the results.

Step 6: Examine the Results

Examine the results to see the changes that were made. If nothing was changed, there is no
need to fix the database.
Minor Changes
If only the table charset changed, there is usually nothing to do—especially if the table
contains no text data.
Major Issues

  • If the table engine changed from MyIsam to InnoDb, you will need the help of a
    developer to investigate and resolve the problem.
  • If a missing foreign key, field, or table was added, you will need the help of a developer
    to investigate and resolve the problem.

Step 7: Perform the Repair

If you are satisfied with database repair report and need to fix your live database, you can
either switch your installation to “database2” (because it was repaired), or perform the repair
directly on the live database.

Step 8: A Little Housekeeping

1. Remove the Database Repair file, magento-db-repair-tool-1.2.php from your server.
2. Restore access to your website.

Leave a Comment

Your email address will not be published. Required fields are marked *