Skip to content

Instantly share code, notes, and snippets.

@ajardin
Last active April 6, 2018 20:47
Show Gist options
  • Save ajardin/8814331 to your computer and use it in GitHub Desktop.
Save ajardin/8814331 to your computer and use it in GitHub Desktop.
How to clean up a Magento database
DELETE cce , cceda , ccede , ccei , ccet , ccev FROM catalog_category_entity cce
LEFT JOIN
catalog_category_entity_datetime AS cceda ON cce.entity_id = cceda.entity_id
LEFT JOIN
catalog_category_entity_decimal AS ccede ON cce.entity_id = ccede.entity_id
LEFT JOIN
catalog_category_entity_int AS ccei ON cce.entity_id = ccei.entity_id
LEFT JOIN
catalog_category_entity_text AS ccet ON cce.entity_id = ccet.entity_id
LEFT JOIN
catalog_category_entity_varchar AS ccev ON cce.entity_id = ccev.entity_id
WHERE
cce.level > 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE enterprise_customer_sales_flat_order;
TRUNCATE enterprise_customer_sales_flat_order_address;
TRUNCATE enterprise_customer_sales_flat_quote;
TRUNCATE enterprise_customer_sales_flat_quote_address;
TRUNCATE enterprise_customerbalance;
TRUNCATE enterprise_customerbalance_history;
TRUNCATE enterprise_customersegment_customer;
TRUNCATE enterprise_customersegment_event;
TRUNCATE enterprise_customersegment_segment;
TRUNCATE enterprise_customersegment_website;
TRUNCATE customer_address_entity;
TRUNCATE customer_address_entity_datetime;
TRUNCATE customer_address_entity_decimal;
TRUNCATE customer_address_entity_int;
TRUNCATE customer_address_entity_text;
TRUNCATE customer_address_entity_varchar;
TRUNCATE customer_entity;
TRUNCATE customer_entity_datetime;
TRUNCATE customer_entity_decimal;
TRUNCATE customer_entity_int;
TRUNCATE customer_entity_text;
TRUNCATE customer_entity_varchar;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE catalog_category_product;
TRUNCATE catalog_product_bundle_option;
TRUNCATE catalog_product_bundle_option_value;
TRUNCATE catalog_product_bundle_selection;
TRUNCATE catalog_product_entity;
TRUNCATE catalog_product_entity_datetime;
TRUNCATE catalog_product_entity_decimal;
TRUNCATE catalog_product_entity_gallery;
TRUNCATE catalog_product_entity_int;
TRUNCATE catalog_product_entity_media_gallery;
TRUNCATE catalog_product_entity_media_gallery_value;
TRUNCATE catalog_product_entity_text;
TRUNCATE catalog_product_entity_tier_price;
TRUNCATE catalog_product_entity_varchar;
TRUNCATE catalog_product_link;
TRUNCATE catalog_product_link_attribute;
TRUNCATE catalog_product_link_attribute_decimal;
TRUNCATE catalog_product_link_attribute_int;
TRUNCATE catalog_product_link_attribute_varchar;
TRUNCATE catalog_product_option;
TRUNCATE catalog_product_option_price;
TRUNCATE catalog_product_option_title;
TRUNCATE catalog_product_option_type_price;
TRUNCATE catalog_product_option_type_title;
TRUNCATE catalog_product_option_type_value;
TRUNCATE catalog_product_relation;
TRUNCATE catalog_product_super_attribute;
TRUNCATE catalog_product_super_attribute_label;
TRUNCATE catalog_product_super_attribute_pricing;
TRUNCATE catalog_product_super_link;
TRUNCATE catalog_product_website;
SET FOREIGN_KEY_CHECKS = 1;
SET FOREIGN_KEY_CHECKS = 0;
TRUNCATE enterprise_sales_creditmemo_grid_archive;
TRUNCATE enterprise_sales_invoice_grid_archive;
TRUNCATE enterprise_sales_order_grid_archive;
TRUNCATE enterprise_sales_shipment_grid_archive;
TRUNCATE enterprise_scheduled_operations;
TRUNCATE sales_bestsellers_aggregated_daily;
TRUNCATE sales_bestsellers_aggregated_monthly;
TRUNCATE sales_bestsellers_aggregated_yearly;
TRUNCATE sales_billing_agreement;
TRUNCATE sales_billing_agreement_order;
TRUNCATE sales_flat_creditmemo;
TRUNCATE sales_flat_creditmemo_comment;
TRUNCATE sales_flat_creditmemo_grid;
TRUNCATE sales_flat_creditmemo_item;
TRUNCATE sales_flat_invoice;
TRUNCATE sales_flat_invoice_comment;
TRUNCATE sales_flat_invoice_grid;
TRUNCATE sales_flat_invoice_item;
TRUNCATE sales_flat_order;
TRUNCATE sales_flat_order_address;
TRUNCATE sales_flat_order_grid;
TRUNCATE sales_flat_order_item;
TRUNCATE sales_flat_order_payment;
TRUNCATE sales_flat_order_status_history;
TRUNCATE sales_flat_quote;
TRUNCATE sales_flat_quote_address;
TRUNCATE sales_flat_quote_address_item;
TRUNCATE sales_flat_quote_item;
TRUNCATE sales_flat_quote_item_option;
TRUNCATE sales_flat_quote_payment;
TRUNCATE sales_flat_quote_shipping_rate;
TRUNCATE sales_flat_shipment;
TRUNCATE sales_flat_shipment_comment;
TRUNCATE sales_flat_shipment_grid;
TRUNCATE sales_flat_shipment_item;
TRUNCATE sales_flat_shipment_track;
TRUNCATE sales_invoiced_aggregated;
TRUNCATE sales_invoiced_aggregated_order;
TRUNCATE sales_order_aggregated_created;
TRUNCATE sales_order_aggregated_updated;
TRUNCATE sales_order_status;
TRUNCATE sales_order_status_label;
TRUNCATE sales_order_status_state;
TRUNCATE sales_order_tax;
TRUNCATE sales_order_tax_item;
TRUNCATE sales_payment_transaction;
TRUNCATE sales_recurring_profile;
TRUNCATE sales_recurring_profile_order;
TRUNCATE sales_refunded_aggregated;
TRUNCATE sales_refunded_aggregated_order;
TRUNCATE sales_shipping_aggregated;
TRUNCATE sales_shipping_aggregated_order;
TRUNCATE salesrule;
TRUNCATE salesrule_coupon;
TRUNCATE salesrule_coupon_usage;
TRUNCATE salesrule_customer;
TRUNCATE salesrule_label;
TRUNCATE salesrule_product_attribute;
SET FOREIGN_KEY_CHECKS = 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment