Magento MySQL DEV Datenbank aufräumen

folder_openBlog, Webentwicklung
commentKeine Kommentare

Im Laufe der Zeit häufen sich in der Magento Datenbank viele tausende Einträge in den Log-Tabellen der Datenbank von Magento an. Oftmals werden dabei mehrere Hundert Megabyte an Daten produziert, die die Datenbank unnötig vergrößern und zumüllen.  Dann heißt es aufräumen. Aber die Datenbanken schnell und einfach zu bereinigen, ist dann oftmals gar nicht so leicht, wenn man nicht weiß, wo man anfangen kann. 

Mit dieser SQL-Abfrage die Du per Copy & Paste nutzen kannst, geht es recht schnell und Du hast die Möglichkeit, bestimmte Bereiche vor dem Aufräumen zu selektieren und auszuschließen.

Achtung – Nicht für Livebetrieb gedacht:
Damit werden alle Bestellung, Kunden, Besuchereinträge und alle Logs gelöscht, so dass nur noch das reine Magento übrig bleibt.
Im Livebetrieb, würde ich nur die Einträge aus dem Bereich — Log tables & — Miscellaneous nutzen.

SQL SNIPPET zur Datenbankbereinigung für Testumgebungen

Öffne Deine Datenbank z.B. mit PhpMyAdmin und führe diesen SQL Befehl aus:

Anzeige

SET FOREIGN_KEY_CHECKS=0;
-- Customers
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;

-- Customer Addresses
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`;

-- Quotes
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`;

-- Orders
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`;

-- Invoices
TRUNCATE `sales_flat_invoice`;
TRUNCATE `sales_flat_invoice_comment`;
TRUNCATE `sales_flat_invoice_grid`;
TRUNCATE `sales_flat_invoice_item`;

-- Shipments
TRUNCATE `sales_flat_shipment`;
TRUNCATE `sales_flat_shipment_comment`;
TRUNCATE `sales_flat_shipment_grid`;
TRUNCATE `sales_flat_shipment_item`;
TRUNCATE `sales_flat_shipment_track`;

-- Sales Order Tax
TRUNCATE `sales_order_tax`;
TRUNCATE `sales_order_tax_item`;

-- Creditmemos
TRUNCATE `sales_flat_creditmemo`;
TRUNCATE `sales_flat_creditmemo_comment`;
TRUNCATE `sales_flat_creditmemo_grid`;
TRUNCATE `sales_flat_creditmemo_item`;

-- Aggregated report tables
TRUNCATE `coupon_aggregated`;
TRUNCATE `coupon_aggregated_order`;
TRUNCATE `coupon_aggregated_updated`;
TRUNCATE `report_viewed_product_aggregated_daily`;
TRUNCATE `report_viewed_product_aggregated_monthly`;
TRUNCATE `report_viewed_product_aggregated_yearly`;
TRUNCATE `sales_bestsellers_aggregated_daily`;
TRUNCATE `sales_bestsellers_aggregated_monthly`;
TRUNCATE `sales_bestsellers_aggregated_yearly`;
TRUNCATE `sales_invoiced_aggregated`;
TRUNCATE `sales_invoiced_aggregated_order`;
TRUNCATE `sales_order_aggregated_created`;
TRUNCATE `sales_order_aggregated_updated`;
TRUNCATE `sales_refunded_aggregated`;
TRUNCATE `sales_refunded_aggregated_order`;
TRUNCATE `sales_shipping_aggregated`;
TRUNCATE `sales_shipping_aggregated_order`;
TRUNCATE `tax_order_aggregated_created`;
TRUNCATE `tax_order_aggregated_updated`;

-- Log tables
TRUNCATE `log_customer`;
TRUNCATE `log_quote`;
TRUNCATE `log_summary`;
TRUNCATE `log_summary_type`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `log_visitor_online`;

-- Miscellaneous
TRUNCATE `catalogsearch_query`;
TRUNCATE `index_event`;
TRUNCATE `index_process_event`;
TRUNCATE `report_event`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;

SET FOREIGN_KEY_CHECKS=1;

Danach sind alle unnötigen Einträge entfernt.

Für Livebetrieb


-- Log tables
TRUNCATE `log_customer`;
TRUNCATE `log_quote`;
TRUNCATE `log_summary`;
TRUNCATE `log_summary_type`;
TRUNCATE `log_url`;
TRUNCATE `log_url_info`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
TRUNCATE `log_visitor_online`;

-- Miscellaneous
TRUNCATE `catalogsearch_query`;
TRUNCATE `index_event`;
TRUNCATE `index_process_event`;
TRUNCATE `report_event`;
TRUNCATE `report_viewed_product_index`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;

Alle Datenquellen

BitBucket Snippet
Github Gist

Bildquelle: Pixelio | 685720_original_R_K_B_by_Maik Schwertle_pixelio.de

Tags: ,

Related Posts

Kommentar verfassen

Menü