Magento数据库修复工具Magento Database Repair Tool

3,363 人次阅读
2 条评论

共计 3849 个字符,预计需要花费 10 分钟才能阅读完成。

Magento数据库结构极其复杂,如果遇到数据库结构错误,想手动检查恢复简直是不可能的事情。好在Magento官方提供了一个非常不错的数据库修复工具,Magento Database Repair Tool,目前的版本是1.1。 Magento数据库修复工具的使用非常简单,只有一个简单的php文件。下载之后解压到任何可以通过web服务器访问的地方。在介绍使用方式之…

Magento数据库结构极其复杂,如果遇到数据库结构错误,想手动检查恢复简直是不可能的事情。好在Magento官方提供了一个非常不错的数据库修复工具,Magento Database Repair Tool,目前的版本是1.1。

The Database Repair Tool compares 2 databases (reference [”corrupted”] and target), and updates the target database so it has the same structure as the reference database by doing the following:

  • Adds missing tables, or repairs them to have the same engine type and charset
  • Adds missing fields or repairs them
  • Removes inconsistent data from tables that have 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.

Usage Instructions

Crash-course for the impatient

Install the same version of Magento you’re using into a clean database. Use the new database as “reference” and the current database as “corrupted”.

That’s it :)

Below come step-by-step instructions.

Test it before running on a Production Environment!

Warning! Before running the repair tool on a production environment, make sure you have tested it before on a development environment. Make sure to create a backup of your original database before running this tool

It is also highly encouraged to restrict access to your website while repairing the database. Here is an example of restricting your Magento instance to your IP address exclusively. Other visitors, including search spiders, will get the HTTP 503 Service Unavailable error.

Create a file 503.php in your Magento installation root:

  1. <?php
  2. header(‘HTTP/1.1 503 Service Unavailable’);
  3. header(‘Content-Type: text/plain; charset=UTF-8’);
  4. echo “503 Service Unavailable”;

In .htaccess or in Apache server configuration, add the following rewrite rule:

Magento数据库修复工具Magento Database Repair Tool

Where 127.0.0.1 (note the backslashes before dots) should be replaced with your IP-address.

Once you save this .htaccess file or reload Apache configuration, your site will be down until you restore the initial state.

Step-by step

  1. Download Magento database repair tool archive from the download page
  2. Uncompress the archive
  3. Put the magento-db-repair-tool-1.0.php into any folder on your server
  4. Backup your existing database to have ability to restore it if anything goes wrong
  5. Clone it as new database on the same server. Let’s call it “database2”
  6. Create an empty database (”database3”)
  7. Either copy your entire Magento folder (without cache and sessions) into a new one and install there into “database3” (By editing local.xml with credentials for the newly created “database3”);
  8. Or if you already restricted access to your Magento instance, you may just change your database credentials into “database3”, clean cache and launch Magento once: it will be installed automatically.

At this point you should have the clone of your original database in “database2” and a brand new “database3” with empty Magento installed.

  1. Enter access credentials to “database2” as “corrupted” database and to “database3” as “reference” database
  2. Set table prefixes, if applicable
  3. Press “Continue” and you will see result screen where you will see what was done to the “corrupted” database.

Magento数据库修复工具Magento Database Repair Tool

Explanation of the report:

  1. If nothing was changed, then there is no need to fix your database
  2. Only table charset was changed — usually there is no need to worry about it, especially if these tables don’t have text data
  3. Table engine was changed from MyIsam to InnoDb — major issue. Needs developer for investigation
  4. Added missing foreign key or field (or even a table!) — major/fatal issue. Ask a developer for help.

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

Don’t forget to remove the magento-db-repair-tool-1.0.php and restore access to website when you are done

Magento数据库修复工具的使用非常简单,只有一个简单的php文件。下载之后解压到任何可以通过web服务器访问的地方。在介绍使用方式之 前,我们必须根据当前的Magento版本,重新安装一个Magento,这样做是为了在修复数据库的时候能够有一个正常无错的Magento数据库版本 参照。

正确填写上述的信息之 后,点击Continue按钮。即可开始数据库的修复过程。该过程根据需要修复的Magento的数据库的破损程度,在完成之前,切记不要关闭窗口。

Magento数据库修复工具地址:http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/db-repair-tool

正文完
 0
评论(2 条评论)
BadFire
2012-09-01 15:47:49 回复

确实很不错的代码,帮了大忙。

 Windows  Firefox  美国加利福尼亚旧金山
    2012-09-01 16:13:22 回复

    有用的时候方能体现作用。曾经也是找了许久才有这段代码。

     Windows  Firefox  美国加利福尼亚旧金山