Deleting customer data in Magento

Customers can be added as well as deleted from Magento admin. To delete customers login to Magento Admin and in the menu select Customers >> Manage Customers.

Manage Customers

This displays the customers listing grid. Now select the customers you want to delete by checking the checkbox in each customer row and then in the actions drop down select “Delete” and click the “Submit” button. Also you can click on the “Edit” link to open the customer edit screen; the edit page has a “Delete” button, click it to delete the customer.

Manage Customer

If you are comfortable working with database then you may run queries mentioned below using MySql client to delete the customer data but be sure to take a database backup before working on it so that you can restore it if anything goes wrong.

The following queries delete the customer and the customer address data.


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

TRUNCATE `log_customer`;

ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;

ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;

ALTER TABLE `log_customer` AUTO_INCREMENT=1;

A customer makes searches on website, subscribes to newsletter, tags product, participates in polls, adds products to wishlist; so if you want to delete tables related to it then you can run the below queries.


-- Search
TRUNCATE `catalogsearch_query`;
TRUNCATE `catalogsearch_fulltext`;
TRUNCATE `catalogsearch_result`;
ALTER TABLE `catalogsearch_query` AUTO_INCREMENT=1;
ALTER TABLE `catalogsearch_fulltext` AUTO_INCREMENT=1;
ALTER TABLE `catalogsearch_result` AUTO_INCREMENT=1;

-- Polls
TRUNCATE `poll`;
TRUNCATE `poll_answer`;
TRUNCATE `poll_store`;
TRUNCATE `poll_vote`;
ALTER TABLE `poll` AUTO_INCREMENT=1;
ALTER TABLE `poll_answer` AUTO_INCREMENT=1;
ALTER TABLE `poll_store` AUTO_INCREMENT=1;
ALTER TABLE `poll_vote` AUTO_INCREMENT=1;

-- Newsletter
TRUNCATE `newsletter_queue`;
TRUNCATE `newsletter_queue_link`;
TRUNCATE `newsletter_subscriber`;
TRUNCATE `newsletter_problem`;
TRUNCATE `newsletter_queue_store_link`;
ALTER TABLE `newsletter_queue` AUTO_INCREMENT=1;
ALTER TABLE `newsletter_subscriber` AUTO_INCREMENT=1;
ALTER TABLE `newsletter_problem` AUTO_INCREMENT=1;
ALTER TABLE `newsletter_queue_store_link` AUTO_INCREMENT=1;

--
-- Wishlist
--
TRUNCATE `wishlist`;
TRUNCATE `wishlist_item`;
TRUNCATE `wishlist_item_option`;

--
-- Tags
--
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_properties';
TRUNCATE `tag_summary`;

TRUNCATE `product_alert_price`;
TRUNCATE `product_alert_stock`;

TRUNCATE `report_compared_product_index`;
TRUNCATE `report_viewed_product_index`;

A customer makes purchases on website and provide ratings/reviews for the products purchased so if you need, you can identify the tables related to sales, coupons and ratings/reviews and truncate them also.

For deleting the sales order data you can refer to the post “Deleting test orders in Magento”.

Leave a Comment

Back to top