Skip to content

Instantly share code, notes, and snippets.

@benjick
Forked from mrkhoa99/Clean up database Magento 2
Last active May 14, 2020 09:22
Show Gist options
  • Save benjick/003710f752c4dad47af00526af76cd20 to your computer and use it in GitHub Desktop.
Save benjick/003710f752c4dad47af00526af76cd20 to your computer and use it in GitHub Desktop.
Clean up database Magento 2 for local enviroment
# Orders, Invoices, Shipments
DELETE FROM sales_order;
DELETE FROM sales_creditmemo_comment;
DELETE FROM sales_creditmemo_item;
DELETE FROM sales_creditmemo;
DELETE FROM sales_creditmemo_grid;
DELETE FROM sales_invoice_comment;
DELETE FROM sales_invoice_item;
DELETE FROM sales_invoice;
DELETE FROM sales_invoice_grid;
DELETE FROM quote_address_item;
DELETE FROM quote_item_option;
DELETE FROM quote;
DELETE FROM quote_address;
DELETE FROM quote_item;
DELETE FROM quote_payment;
DELETE FROM quote_shipping_rate;
DELETE FROM quote_id_mask;
DELETE FROM sales_shipment_comment;
DELETE FROM sales_shipment_item;
DELETE FROM sales_shipment_track;
DELETE FROM sales_shipment;
DELETE FROM sales_shipment_grid;
DELETE FROM sales_order_address;
DELETE FROM sales_order_item;
DELETE FROM sales_order_payment;
DELETE FROM sales_order_status_history;
DELETE FROM sales_order_grid;
DELETE FROM sales_order_tax;
# Delete Order, Invoice, Shipment, Refund aggregated
DELETE FROM sales_invoiced_aggregated;
DELETE FROM sales_invoiced_aggregated_order;
DELETE FROM sales_order_aggregated_created;
DELETE FROM sales_order_aggregated_updated;
DELETE FROM sales_refunded_aggregated;
DELETE FROM sales_refunded_aggregated_order;
DELETE FROM sales_shipping_aggregated;
DELETE FROM sales_shipping_aggregated_order;
# Reward History
DELETE FROM magento_reward_history;
# Report Event
DELETE FROM sales_bestsellers_aggregated_daily;
DELETE FROM sales_bestsellers_aggregated_monthly;
DELETE FROM sales_bestsellers_aggregated_yearly;
DELETE FROM report_viewed_product_index;
DELETE FROM report_viewed_product_aggregated_daily;
DELETE FROM report_viewed_product_aggregated_monthly;
DELETE FROM report_viewed_product_aggregated_yearly;
DELETE FROM product_alert_stock;
DELETE FROM search_query;
DELETE FROM catalogsearch_fulltext_scope1;
# Extensions
DELETE FROM mageplaza_smtp_log;
SELECT
table_schema AS `Database`,
table_name AS `Table`,
round(((data_length + index_length) / 1024 / 1024), 2) `Size in MB`
FROM
information_schema.TABLES
ORDER BY
(data_length + index_length)
DESC;
./n98-magerun2.phar db:dump --strip="@stripped @aggregated @customers @development @quotes @replica @sales @search"
./n98-magerun2.phar db:dump --strip="@development aw_arep_* m2epro_* mageplaza_smtp_log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment