`
天梯梦
  • 浏览: 13763708 次
  • 性别: Icon_minigender_2
  • 来自: 洛杉矶
社区版块
存档分类
最新评论

清空magento所有的产品数据 Delete magento category / products by SQL

 
阅读更多

Magento 1.5 and 1.6

 

Truncate products

This should remove all the products and their related records.

TRUNCATE TABLE `catalog_product_bundle_option`;
    TRUNCATE TABLE `catalog_product_bundle_option_value`;
    TRUNCATE TABLE `catalog_product_bundle_selection`;
    TRUNCATE TABLE `catalog_product_entity_datetime`;
    TRUNCATE TABLE `catalog_product_entity_decimal`;
    TRUNCATE TABLE `catalog_product_entity_gallery`;
    TRUNCATE TABLE `catalog_product_entity_int`;
    TRUNCATE TABLE `catalog_product_entity_media_gallery`;
    TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
    TRUNCATE TABLE `catalog_product_entity_text`;
    TRUNCATE TABLE `catalog_product_entity_tier_price`;
    TRUNCATE TABLE `catalog_product_entity_varchar`;
    TRUNCATE TABLE `catalog_product_link`;
    TRUNCATE TABLE `catalog_product_link_attribute`;
    TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
    TRUNCATE TABLE `catalog_product_link_attribute_int`;
    TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
    TRUNCATE TABLE `catalog_product_link_type`;
    TRUNCATE TABLE `catalog_product_option`;
    TRUNCATE TABLE `catalog_product_option_price`;
    TRUNCATE TABLE `catalog_product_option_title`;
    TRUNCATE TABLE `catalog_product_option_type_price`;
    TRUNCATE TABLE `catalog_product_option_type_title`;
    TRUNCATE TABLE `catalog_product_option_type_value`;
    TRUNCATE TABLE `catalog_product_super_attribute`;
    TRUNCATE TABLE `catalog_product_super_attribute_label`;
    TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
    TRUNCATE TABLE `catalog_product_super_link`;
    TRUNCATE TABLE `catalog_product_enabled_index`;
    TRUNCATE TABLE `catalog_product_website`;
    TRUNCATE TABLE `catalog_product_entity`;
     
    TRUNCATE TABLE `cataloginventory_stock`;
    TRUNCATE TABLE `cataloginventory_stock_item`;
    TRUNCATE TABLE `cataloginventory_stock_status`;
     
    INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
    INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
    INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');
 

n magento 1.5 you need to add in cataloginventory_stock., I added a record with stock_id 1 and stock_name to Default. Without this there will be a foreign key constraint fail, see http://www.magentocommerce.com/boards/v/viewthread/41764/#t169087 for further explanation

 

Truncate categories

This should remove all the categories and their related records. It will also create new Root category.

TRUNCATE TABLE `catalog_category_entity`;
    TRUNCATE TABLE `catalog_category_entity_datetime`;
    TRUNCATE TABLE `catalog_category_entity_decimal`;
    TRUNCATE TABLE `catalog_category_entity_int`;
    TRUNCATE TABLE `catalog_category_entity_text`;
    TRUNCATE TABLE `catalog_category_entity_varchar`;
    TRUNCATE TABLE `catalog_category_product`;
    TRUNCATE TABLE `catalog_category_product_index`;
     
    INSERT  INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
    INSERT  INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1);
    INSERT  INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,33,0,1,'root-catalog'),(3,3,31,0,2,'Default Category'),(4,3,39,0,2,'PRODUCTS'),(5,3,33,0,2,'default-category');
     
    /**** Magento ver. 1.6.x.x ****/
     
    TRUNCATE TABLE `catalog_category_entity`;
    TRUNCATE TABLE `catalog_category_entity_datetime`;
    TRUNCATE TABLE `catalog_category_entity_decimal`;
    TRUNCATE TABLE `catalog_category_entity_int`;
    TRUNCATE TABLE `catalog_category_entity_text`;
    TRUNCATE TABLE `catalog_category_entity_varchar`;
    TRUNCATE TABLE `catalog_category_product`;
    TRUNCATE TABLE `catalog_category_product_index`;
     
    INSERT  INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'0000-00-00 00:00:00','0000-00-00 00:00:00','1',1,0,1), (2,3,3,1,'0000-00-00 00:00:00','0000-00-00 00:00:00','1/2','1','1','0');
    INSERT  INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,36,0,2,1),(3,3,61,0,2,1),(4,3,44,0,2,NULL),(5,3,45,0,2,1),(6,3,62,0,2,1),(7,3,63,0,2,1),(8,3,64,0,2,NULL);
    INSERT  INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,31,0,1,'Root Catalog'),(2,3,35,0,2,'Default Category'),(3,3,37,0,2,'default-category'),(4,3,40,0,2,NULL),(5,3,43,0,2,'PRODUCTS'),(6,3,52,0,2,NULL),(7,3,55,0,2,NULL);
     
    /**** Magento ver. 1.6.x.x ****/
 

Truncate customers

This should remove all the customers and their related records.

    TRUNCATE TABLE `customer_address_entity`;
    TRUNCATE TABLE `customer_address_entity_datetime`;
    TRUNCATE TABLE `customer_address_entity_decimal`;
    TRUNCATE TABLE `customer_address_entity_int`;
    TRUNCATE TABLE `customer_address_entity_text`;
    TRUNCATE TABLE `customer_address_entity_varchar`;
    TRUNCATE TABLE `customer_entity`;
    TRUNCATE TABLE `customer_entity_datetime`;
    TRUNCATE TABLE `customer_entity_decimal`;
    TRUNCATE TABLE `customer_entity_int`;
    TRUNCATE TABLE `customer_entity_text`;
    TRUNCATE TABLE `customer_entity_varchar`;
 

Magento 1.7

 

I was writing a bulk category/product import script for magento 1.7. For debugging I had to frequently clear all the erroneous data inserted while coding and run my script again and again. Searching for an easy solution I came into this magento wiki that has the queries to delete all the products and categories for Magento 1.5 and 1.6. In 1.7 the attribute ids are not same so I needed an updated one. So here is the queries for 1.7 to reset your product / category tables to the initial position just after fresh magento installation.

 

Please note the first and last sql commands that are used to ignore the foreign key constraints. Without these 2 lines, you will get error.

 

    SET FOREIGN_KEY_CHECKS = 0;

    TRUNCATE TABLE `catalog_product_bundle_option`;
    TRUNCATE TABLE `catalog_product_bundle_option_value`;
    TRUNCATE TABLE `catalog_product_bundle_selection`;
    TRUNCATE TABLE `catalog_product_entity_datetime`;
    TRUNCATE TABLE `catalog_product_entity_decimal`;
    TRUNCATE TABLE `catalog_product_entity_gallery`;
    TRUNCATE TABLE `catalog_product_entity_int`;
    TRUNCATE TABLE `catalog_product_entity_media_gallery`;
    TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
    TRUNCATE TABLE `catalog_product_entity_text`;
    TRUNCATE TABLE `catalog_product_entity_tier_price`;
    TRUNCATE TABLE `catalog_product_entity_varchar`;
    TRUNCATE TABLE `catalog_product_link`;
    TRUNCATE TABLE `catalog_product_link_attribute`;
    TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
    TRUNCATE TABLE `catalog_product_link_attribute_int`;
    TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
    TRUNCATE TABLE `catalog_product_link_type`;
    TRUNCATE TABLE `catalog_product_option`;
    TRUNCATE TABLE `catalog_product_option_price`;
    TRUNCATE TABLE `catalog_product_option_title`;
    TRUNCATE TABLE `catalog_product_option_type_price`;
    TRUNCATE TABLE `catalog_product_option_type_title`;
    TRUNCATE TABLE `catalog_product_option_type_value`;
    TRUNCATE TABLE `catalog_product_super_attribute`;
    TRUNCATE TABLE `catalog_product_super_attribute_label`;
    TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
    TRUNCATE TABLE `catalog_product_super_link`;
    TRUNCATE TABLE `catalog_product_enabled_index`;
    TRUNCATE TABLE `catalog_product_website`;
    TRUNCATE TABLE `catalog_product_entity`;

    TRUNCATE TABLE `cataloginventory_stock`;
    TRUNCATE TABLE `cataloginventory_stock_item`;
    TRUNCATE TABLE `cataloginventory_stock_status`;

    TRUNCATE TABLE `catalog_category_entity`;
    TRUNCATE TABLE `catalog_category_entity_datetime`;
    TRUNCATE TABLE `catalog_category_entity_decimal`;
    TRUNCATE TABLE `catalog_category_entity_int`;
    TRUNCATE TABLE `catalog_category_entity_text`;
    TRUNCATE TABLE `catalog_category_entity_varchar`;
    TRUNCATE TABLE `catalog_category_product`;
    TRUNCATE TABLE `catalog_category_product_index`;

    INSERT INTO `catalog_category_entity` (`entity_id`, `entity_type_id`, `attribute_set_id`, `parent_id`, `created_at`, `updated_at`, `path`, `position`, `level`, `children_count`) VALUES (1, 3, 0, 0, ’2012-06-17 22:20:47′, ’2012-06-17 22:20:47′, ’1′, 0, 0, 1), (2, 3, 3, 1, ’2012-06-17 22:20:47′, ’2012-06-17 22:20:47′, ’1/2′, 1, 1, 0);
    INSERT INTO `catalog_category_entity_int` (`value_id`, `entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (1, 3, 67, 0, 1, 1), (2, 3, 67, 1, 1, 1), (3, 3, 42, 0, 2, 1), (4, 3, 67, 0, 2, 1), (5, 3, 42, 1, 2, 1), (6, 3, 67, 1, 2, 1);
    INSERT INTO `catalog_category_entity_varchar` (`value_id`, `entity_type_id`, `attribute_id`, `store_id`, `entity_id`, `value`) VALUES (1, 3, 41, 0, 1, ‘Root Catalog’), (2, 3, 41, 1, 1, ‘Root Catalog’), (3, 3, 43, 1, 1, ‘root-catalog’), (4, 3, 41, 0, 2, ‘Default Category’), (5, 3, 41, 1, 2, ‘Default Category’), (6, 3, 49, 1, 2, ‘PRODUCTS’), (7, 3, 43, 1, 2, ‘default-category’);

    INSERT INTO `catalog_product_link_type` (`link_type_id`, `code`) VALUES (1, ‘relation’), (3, ‘super’), (4, ‘up_sell’), (5, ‘cross_sell’);
    INSERT INTO `catalog_product_link_attribute` (`product_link_attribute_id`, `link_type_id`, `product_link_attribute_code`, `data_type`) VALUES (1, 1, ‘position’, ‘int’), (2, 3, ‘position’, ‘int’), (3, 3, ‘qty’, ‘decimal’), (4, 4, ‘position’, ‘int’), (5, 5, ‘position’, ‘int’);
    INSERT INTO `cataloginventory_stock` (`stock_id`, `stock_name`) VALUES (1, ‘Default’);

    SET FOREIGN_KEY_CHECKS = 1;
 

 

from: http://www.imranulhoque.com/magento/reset-delete-magento-category-products-by-sql-for-magento-version-1-7/

 

 

 

 

分享到:
评论

相关推荐

    magento导出数据sql

    在执行大规模导出时,应考虑到数据库性能,避免一次性导出所有数据,而是分批进行。 2. **数据权限**:确保你有适当的数据库访问权限,执行导出操作可能需要读取、写入甚至修改数据的权限。 3. **数据安全**:导出...

    magento删除订单sql

    在Magento系统中,有时可能需要清理或删除特定的订单数据,比如当测试环境中积累了大量无用的订单记录,或者在某些特殊情况下需要手动清除错误的订单等。本文将详细介绍如何通过编写SQL语句来实现这一操作,并确保...

    magento数据结构分析

    标题:“Magento数据结构分析” 描述:“Magento数据字典”提供了对Magento系统中各种数据库表的深入理解,这对于理解和优化Magento的性能至关重要。 一、Magento数据结构解析 Magento是一款功能强大的电子商务...

    magento产品名称及描述批量修改sql

    以上就是使用SQL批量修改Magento产品名称和描述的方法。记住,尽管这种方法效率高,但必须谨慎操作,以免误改数据。在进行任何数据库级别的操作时,确保你对Magento的数据库结构有深入理解,并遵循最佳实践。

    magento批量制作产品数据教程

    - 将图片文件夹上传到服务器的`magento/media/import`目录下。如果图片数量大,可先压缩再上传,到达后在控制面板解压。 4. **上传数据包**: - 使用FTP工具将CSV数据包上传至服务器的`var/import`目录下。若无此...

    magento SQL常用命令

    根据提供的文件信息,我们可以归纳出一系列与Magento相关的SQL命令及应用场景。Magento是一款广泛使用的电子商务平台,对于维护其数据库的操作非常重要。下面将详细解释文件中提到的各个知识点。 ### Magento SQL ...

    Magento1.6样例数据及使用说明

    Magento-sample-data-1.6.1.0这个压缩包就提供了这样的数据集,让你能够在安装Magento 1.6.1.0时预填充商店信息,无需从零开始创建所有内容。 样例数据的安装通常包括以下几个步骤: 1. **下载并解压**: 首先,你...

    magento通过产品名称获取产品id

    在电子商务领域,Magento是一款非常流行的开源电子商务平台,它提供了丰富的功能和灵活性,使得...通过上述步骤,我们可以在Magento系统中有效地通过产品名称获取产品ID,这对于自动化处理和数据分析流程具有重要意义。

    magento-演示数据1.6.1.0

    "magento-演示数据1.6.1.0"是一个专门为Magento 1.6.1.0版本准备的示例数据包,它包含了用于演示和测试 Magento 商店功能的各种数据,如产品、类别、顾客、订单等。 该压缩包文件“magento-sample-data-1.6.1.0”...

    magento数据库批量导出产品及自定义属性语句

    首先,我们要理解Magento的产品数据存储结构。Magento将产品信息分散在多个数据库表中,主要包括`catalog_product_entity`作为主产品表,以及一系列以`_attribute`结尾的表来存储产品的不同属性。自定义属性则存储在...

    magento的数据传输功能

    - 在此之前,最好再次确认所有数据都已经成功迁移,以防万一。 #### 四、注意事项 - **备份数据**:在开始任何迁移工作之前,务必对当前环境的数据进行全面备份。 - **环境兼容性**:确保新版本的Magento与当前...

    magento商城数据库

    这会创建 Magento 需要的所有表,包括 `catalog_product_entity`(产品信息)、`sales_flat_order`(订单数据)、`customer_entity`(客户信息)等。 4. **加载样本数据**:除了基础架构,这个包可能还包含一些示例...

    我终于实现了 把 firephp 集成进 magento了 终于能监测 sql了

    标题提到的"我终于实现了把FirePHP集成进Magento了,终于能监测SQL了",这是一个关于将FirePHP日志框架与Magento电子商务平台整合的成就,使得开发者能够更方便地追踪和分析系统中的SQL查询。下面将详细阐述这一集成...

    Magento系统请求响应流程图

    Controller 使用 Object Models,这一步骤中,Magento 的 Model 开始配置(加载 config.xml, system.xml, layout 下的*.xml 等所有配置文件)。Object Model 是 Magento 的核心组件之一,负责处理数据和业务逻辑。 ...

    zencart 数据迁移到magento 数据库操作

    3. 测试:在导入所有数据后,进行详尽的测试,确保所有功能正常运行,无数据丢失或错误。 文件"magento批量导入.txt"可能包含了关于Magento批量导入功能的详细指南,这对于整个迁移过程至关重要。请仔细阅读并遵循...

    Magento1产品预览

    在Magento1中,产品预览功能是提升用户体验的关键部分,它允许用户在不实际进入产品详情页面的情况下预览产品的图片。这样的设计可以提高网站的交互性和用户满意度,因为他们能够快速浏览商品,决定是否需要进一步...

    magento站点首页显示新产品及产品数量

    ### Magento站点首页显示新产品及产品数量 在Magento中,首页是吸引客户的第一界面,因此如何有效地展示新产品及其数量显得尤为重要。本文将详细介绍如何在Magento站点的首页上展示新产品及其数量,并提供具体的...

    Magento批量产品多图上传

    "Magento批量产品多图上传"是针对Magento系统的一个功能模块,主要解决了在Magento 1.7版本中一次性上传多个产品图片的问题,极大地提高了产品管理效率。 在默认情况下,Magento允许用户为每个产品添加多张图片,但...

    Magento深入理解Magento

    - 清空Magento缓存。 - 在后台管理界面中,进入System -> Configuration -> Advanced。 - 展开“DisableModulesOutput”选项。 - 确认“App_Configviewer”是否显示在列表中。 4. **添加模块逻辑** 至此,您...

    Magento插件(DeleteOrder)

    "DeleteOrder"插件是针对Magento系统的一个特定解决方案,解决了在默认情况下,Magento系统不支持直接删除订单的问题。这个插件允许用户在必要时永久删除订单,但需要注意的是,一旦订单被删除,数据将无法恢复,...

Global site tag (gtag.js) - Google Analytics