davidselo
davidselo

Reputation: 1325

Remove all Customers in Magento

I need remove all clients from my Magento install, because they have bad dates. I have 70,000 customers in my developed site. How can I do this with SQL?

Upvotes: 9

Views: 18701

Answers (3)

Bravehartk2
Bravehartk2

Reputation: 1614

Or you just build a shell script and do something like that (not fast, but it is clean):

 /*
 * Starter
 * */
public function run()
{
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    ini_set('memory_limit', '4096M');
    if (!$this->getArg('iknowwhatido') || $this->getArg('iknowwhatido') != 'yes') {
        $this->usageHelp();
        echo "DEACTIVATED (call it with param '-iknowwhatido yes' to make it work!) \n";
        return -1;
    }
    Mage::register('isSecureArea', true);
    $customers = Mage::getModel("customer/customer")->getCollection()->delete();
}

Upvotes: 0

Kervin Ramen
Kervin Ramen

Reputation: 2583

Mage::register('isSecureArea', true);

$customers = Mage::getModel("customer/customer")->getCollection();

foreach ($customers as $customer) {
    $customer->delete();
}

Be sure to know what you are doing though.. You can disable the customer as well if delete is not what you need.

Upvotes: 14

paj
paj

Reputation: 1187

Make a BACKUP and test on a dev server first! This will DELETE all customer data including logs.

SET FOREIGN_KEY_CHECKS=0;
-- reset customers
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;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;

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;
ALTER TABLE log_visitor AUTO_INCREMENT=1;
ALTER TABLE log_visitor_info AUTO_INCREMENT=1;
SET FOREIGN_KEY_CHECKS=1;

Upvotes: 34

Related Questions