Discuz!删除用户后清理垃圾数据

我的软件的用户论坛(http://bbs.akhtm.com)被发广告的灌水机看中了,每天有近千的用户注册,我写了个程序清理这些垃圾,虽然这些用户不能登录了,但是日积月累,数据库还是越来越胖,今天一看,我靠,500多MB了。

研究了一下,原来除了用户主表之外,Discuz!还有一系列存用户扩展信息的关联表,整理出以下8个:

cdb_common_member_profile
cdb_common_credit_rule_log
cdb_common_member_count
cdb_common_member_field_forum
cdb_common_member_field_home
cdb_common_member_status
cdb_common_onlinetime
cdb_ucenter_memberfields

他们和主表的关键的字段都是uid,执行以下SQL语句清理这些垃圾数据:

delete from cdb_common_member_profile where uid not in (select uid from cdb_common_member);
delete from cdb_common_credit_rule_log where uid not in (select uid from cdb_common_member);
delete from cdb_common_member_count where uid not in (select uid from cdb_common_member);
delete from cdb_common_member_field_forum where uid not in (select uid from cdb_common_member);
delete from cdb_common_member_field_home where uid not in (select uid from cdb_common_member);
delete from cdb_common_member_status where uid not in (select uid from cdb_common_member);
delete from cdb_common_onlinetime where uid not in (select uid from cdb_common_member);
delete from cdb_ucenter_memberfields where uid not in (select uid from cdb_common_member);

清理后感觉神清气爽,一下子节省了400多MB的数据库空间。

 评论
 发表评论
姓   名: