【发布时间】:2011-07-13 09:13:00
【问题描述】:
我需要从我的 Magento 安装中删除所有客户端,因为它们的日期不正确。我开发的网站中有 70,000 名客户。我怎样才能用 SQL 做到这一点?
【问题讨论】:
我需要从我的 Magento 安装中删除所有客户端,因为它们的日期不正确。我开发的网站中有 70,000 名客户。我怎样才能用 SQL 做到这一点?
【问题讨论】:
制作备份并首先在开发服务器上进行测试! 这将删除所有客户数据,包括日志。
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;
【讨论】:
Invalid default value for 'created_at'。在开头添加这一行可以解决:/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;(更多:stackoverflow.com/a/23147829/3763649)
Mage::register('isSecureArea', true);
$customers = Mage::getModel("customer/customer")->getCollection();
foreach ($customers as $customer) {
$customer->delete();
}
一定要知道你在做什么。如果删除不是你需要的,你也可以禁用客户。
【讨论】:
或者您只是构建一个 shell 脚本并执行类似的操作(速度不快,但很干净):
/*
* 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();
}
【讨论】: