如何恢复 magento数据库
2011-05-07 11:15
246 查看
The Magento database makes use of foreign key constraints to ensure
database integrity. As an example, if a category is deleted, all
categories below it in the category tree must be deleted too.
If
you make a backup of your Magento database using the built-in backup
function (Admin > System > Tools > Backup), Magento inserts
special statements in the .sql file to avoid foreign key checks when
the tables are restored.
If you backup your Magento database
using other tools, like phpMyAdmin or Navicat, these special statements
will be missing. When you attempt to run the .sql file, you will get
errors like these:
Cannot add or update a child row: a foreign key constraint fails
This
error occurs because the data you are importing is provided table by
table, row by row, without regard to the logical structure and
integrity of the database.
To restore a .sql file backup
without constraint checking, simply add the following statements at the
beginning of your .sql file:
SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;
SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;
SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;
SET NAMES utf8;
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’;
SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;
At the end of the file, add the statements required to turn on constraint checking again:
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT;
SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS;
SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;
SET SQL_NOTES=@OLD_SQL_NOTES;
With these modifications, you should be able to restore your database from a .sql file backup created with any tool.
If
you have similar problems installing the sample database, just add the
same statements to the .sql file containing the sample data.
转载: http://linux.blogbus.com/logs/37279191.html
database integrity. As an example, if a category is deleted, all
categories below it in the category tree must be deleted too.
If
you make a backup of your Magento database using the built-in backup
function (Admin > System > Tools > Backup), Magento inserts
special statements in the .sql file to avoid foreign key checks when
the tables are restored.
If you backup your Magento database
using other tools, like phpMyAdmin or Navicat, these special statements
will be missing. When you attempt to run the .sql file, you will get
errors like these:
Cannot add or update a child row: a foreign key constraint fails
This
error occurs because the data you are importing is provided table by
table, row by row, without regard to the logical structure and
integrity of the database.
To restore a .sql file backup
without constraint checking, simply add the following statements at the
beginning of your .sql file:
SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT;
SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS;
SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION;
SET NAMES utf8;
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE=’NO_AUTO_VALUE_ON_ZERO’;
SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0;
At the end of the file, add the statements required to turn on constraint checking again:
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT;
SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS;
SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION;
SET SQL_NOTES=@OLD_SQL_NOTES;
With these modifications, you should be able to restore your database from a .sql file backup created with any tool.
If
you have similar problems installing the sample database, just add the
same statements to the .sql file containing the sample data.
转载: http://linux.blogbus.com/logs/37279191.html
相关文章推荐
- 如何恢复数据库的误操作?
- 在magento下如何直接操作访问数据库
- SQL2005 如何在没有日志文件的情况下如何恢复MDF数据库文件
- 如何恢复数据库
- Magento-如何新增、更新或者删除数据库中的数据
- 如何通过Mysql的二进制日志恢复数据库数据
- 在非归挡模式下,,如何恢复数据库!!!
- 如何通过 MySQL 的二进制日志恢复数据库数据
- MongoDB的数据库如何备份和恢复?
- 如何恢复一个只有完好数据文件的数据库?
- oracle误删磁盘数据后不能连接数据库 如何恢复
- [转载]如何用SQLDMO在ASP.NET页面下实现数据库的备份与恢复
- 数据库只有mdf文件而没有ldf文件,如何恢复数据库
- 如何恢复数据库的账号 登录名/用户名等
- 数据库-sqlserver2005中执行delete语句后如何恢复
- 如何用SQLDMO在ASP.NET页面下实现数据库的备份与恢复(转载)
- 数据库误操作,如何恢复数据(SQL事务,或数据库还原)
- 详解如何通过Mysql的二进制日志恢复数据库数据
- MongoDB的数据库如何备份和恢复?
- 如何恢复系统数据库?