去评论
dz插件网

discuz x3系列帖子进行手动分表教程

饾暦饾枎饾枒饾枏饾枂饾枅饾枑
2021/12/29 16:14:45
建议post单表超过10G的,考虑分表处理。对mysql不熟悉的请直接在discuz后台操作分表……如果需要付费协助也可以直接联系飘仙不接受白嫖

以下操作可以在不中断论坛访问的情况下进行,但是由于资源使用的问题,严重建议备份数据库并且关闭论坛才进行

创建帖子分表,如
CREATE TABLE pre_forum_post_2 (
pid int(10) unsigned NOT NULL,
fid mediumint(8) unsigned NOT NULL DEFAULT '0',
tid int(10) NOT NULL DEFAULT '0',
first tinyint(1) NOT NULL DEFAULT '0',
author varchar(15) NOT NULL DEFAULT '',
authorid mediumint(8) unsigned NOT NULL DEFAULT '0',
subject varchar(80) NOT NULL DEFAULT '',
dateline int(10) unsigned NOT NULL DEFAULT '0',
message mediumtext NOT NULL,
useip varchar(15) NOT NULL DEFAULT '',
port smallint(6) unsigned NOT NULL DEFAULT '0',
invisible tinyint(1) NOT NULL DEFAULT '0',
anonymous tinyint(1) NOT NULL DEFAULT '0',
usesig tinyint(1) NOT NULL DEFAULT '0',
htmlon tinyint(1) NOT NULL DEFAULT '0',
bbcodeoff tinyint(1) NOT NULL DEFAULT '0',
smileyoff tinyint(1) NOT NULL DEFAULT '0',
parseurloff tinyint(1) NOT NULL DEFAULT '0',
attachment tinyint(1) NOT NULL DEFAULT '0',
rate smallint(6) NOT NULL DEFAULT '0',
ratetimes tinyint(3) unsigned NOT NULL DEFAULT '0',
status int(10) NOT NULL DEFAULT '0',
tags varchar(255) NOT NULL DEFAULT '0',
comment tinyint(1) NOT NULL DEFAULT '0',
replycredit int(10) NOT NULL DEFAULT '0',
position int(8) unsigned NOT NULL AUTO_INCREMENT,
PRIMARY KEY (tid,position),
UNIQUE KEY pid (pid),
KEY fid (fid),
KEY authorid (authorid,invisible),
KEY dateline (dateline),
KEY invisible (invisible),
KEY displayorder (tid,invisible,dateline),
KEY first (tid,first)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
注:注意编码设置和mysql引擎
把帖子从主表拷贝过来
根据经验,大概1000W帖子在一般的存储里面都是能支撑的,结合自身论坛的状况,回复要是不多,估计要200W个主题就会1000W帖子
确定了就开始转移
INSERT INTO pre_forum_post_2 SELECT * FROM pre_forum_post WHERE tid<2000000;
更新thread表记录
update pre_forum_thread set posttableid=2 where tid in (select distinct tid from pre_forum_post_2 where first=1 );
删除主表重复数据
DELETE FROM pre_forum_post WHERE tid in (select distinct tid from pre_forum_post_2);
如果需要划分多个表,重复以上操作即可。