我們在做論壇網站時,經常需要對論壇內容進行批量修改,如果不採用數據庫批量修改,就會把你累爬下,下面是學做網站彙總 DISCUZ 論壇常用批量修改 SQL 語句,根據自己的需要,使用常用 SQL 語句。注意在使用 SQL 語句前,一定要備份自己網站的數據庫。
所有板塊的特殊主題開啓
UPDATE `cdb_forums` SET `allowpostspecial` = '31'
調整某個帖子的點擊數
UPDATE cdb_threads SET views=點擊數 WHERE tid=主題編號;
所有板塊開啓 media 代碼
UPDATE `cdb_forums` SET `allowmediacode` = '1'
調整所有用户最大頭像尺寸 (像素) 為 120
update cdb_settings set value = 120 WHERE variable = 'maxavatarpixel'
一次性關閉板塊 fid20 帖子
UPDATE `cdb_threads` SET `closed` = '1' WHERE `fid` =20 ;
把發帖數為 0 的用户都轉到某個用户組
update cdb_members set groupid = * where posts = 0;
UPDATE `cdb_usergroups` SET `allowinvite` = '1', `inviteprice` = '價格';
開啓全部用户組的邀請註冊權限 並設置價格
replace INTO cdb_settings VALUES ('watermarktype','0');
去除水印圖片類型
update cdb_members set lastpost='1186675200';
調整用户最後登錄時間為 2007 年 8 月 10 日
UPDATE `cdb_forums` SET `status` = '1',
`lastpost` = '' WHERE `fid` =6 LIMIT 1 ;
調整 板塊隱藏的 sql!
完整關閉 supesite 的 sql 語句:
UPDATE `cdb_settings` SET `value` = '' WHERE `variable` = 'supe_siteurl' ;
UPDATE `cdb_settings` SET `value` = '' WHERE `variable` = 'supe_sitename';
UPDATE `cdb_settings` SET `value` = '0' WHERE `variable` = 'supe_status';
UPDATE `cdb_settings` SET `value` = '' WHERE `variable` = 'supe_tablepre';
UPDATE `cdb_settings` SET `value` = '0' WHERE `variable` = 'supe_circlestatus';
將 A 板塊的所有帖子轉到 B 板塊的 C 分類裏
update cdb_threads set fid=B 板塊 ID,typeid=c 分類的 ID where fid=A 板塊 ID;
update cdb_posts set fid=B 板塊 ID where fid=A 板塊 ID;
執行前備份一下數據庫
去除後台管理員 ip 登錄限制
UPDATE `cdb_settings` SET `value` = '' WHERE CONVERT( `variable` USING utf8 ) ='adminipaccess' LIMIT 1 ;
刪除風格 5
delete from cdb_styles where styleid=5 limit 1;
UPDATE `cdb_members` SET `pmsound` = '1'
論壇所有用户短消息提示音修改為提示音 1
delete from cdb_usergroups where groupid = 0
刪除 groupid = 0 的用户組
UPDATE `cdb_forums` SET `alloweditpost` = '1'
所有板塊開啓允許編輯帖子
論壇後台 解除 insenz 綁定語句
delete from cdb_settings where variable='insenz'
論壇後台執行後 就可以 重新註冊和綁定了
關閉遊客瀏覽所有版塊的語句
可以這樣構造 SQL 語句
update cdb_forumfields set viewperm =' 允許瀏覽的用户組的 ID ' where fid in(論壇板塊 ID)
如:
update cdb_forumfields set viewperm =' 1 2 ' where fid in(1,2)
UPDATE `cdb_forumfields` SET `rules` = '板塊規則'
所有板塊的板塊規則設置~!
UPDATE `cdb_forums` SET `jammer` = '1'
開啓所有板塊的幹擾碼
開啓所有會員組邀請註冊的權限
UPDATE cdb_usergroups SET allowinvite=1, allowmailinvite=1, maxinvitenum=10, maxinviteday=15, inviteprice=10;
//allowinvite 允許使用邀請註冊:
//allowmailinvite 允許發送邀請註冊:
//maxinvitenum 24 小時內購買邀請碼最大數量:
//maxinviteday 邀請碼有效期:
//inviteprice 邀請碼購買價格:
修改最高日發帖數
UPDATE `cdb_settings` SET `value` = '昨日發帖數 最高日發帖數' WHERE `variable` ='historyposts' LIMIT 1 ;
昨日發帖數 和 最高日發帖數 修改為你需要的數字即可, 升級完 sql 後, 更新緩存
'昨日發帖數 最高日發帖數' 中間的空格是 tab 鍵~!
UPDATE `cdb_settings` SET `value` = '0' WHERE CONVERT( `variable` USING utf8 ) = 'gzipcompress' LIMIT 1 ;
關閉論壇的 gzip 設置!
批量對用户組禁言
update cdb_members set adminid='-1', groupid='4' where groupid='?';
delete from cdb_threads where authorid=0;
delete from cdb_posts where authorid=0;
批量刪除遊客組的發帖和主題
uid 2000~3000 的會員全部積分清零
update cdb_members set credits=0,extcredits1=0,extcredits2=0,extcredits3=0,extcredits4=0,extcredits5=0,extcredits6=0,extcredits7=0,extcredits8=0 where uid > 2000 and uid < 3000;
指定範圍內的審核主題通過審核
update cdb_threads set displayorder=0 where tid > 最小的 tid and tid < 最大的 tid
指定範圍內的審核帖子通過審核
update cdb_posts set invisible = 0 where tid > 最小的 tid and tid < 最大的 tid
批量刪除未審核通過的帖子和主題
delete from cdb_threads where displayorder=-2;
delete from cdb_posts where invisible=-2;
批量關閉投票
UPDATE cdb_threads SET closed = 1 WHERE special=1
UPDATE `cdb_members` SET `secques` = ''
清空用户安全問答!
清空某個用户組的全部積分 sql:
update cdb_members set credits = 0, extcredits1 = 0, extcredits2 = 0, extcredits3 = 0, extcredits4 = 0, extcredits5 = 0, extcredits6 = 0, extcredits7 = 0, extcredits8 = 0, where groupid = 用户組 id;
update cdb_usergroups set allowtransfer=0
關閉所有用户組的積分轉賬
update cdb_threads set readperm=100 where dateline<1133300000
修改 05 年 11 月 29 日 21 點 33 份 20 秒 前的主題閲讀權限 100
其中 1133300000 是 unix 時間戳 (以秒為單位) 代表 05 年 11 月 29 日 21 點 33 份 20 秒
readperm=100 代表閲讀權限
把 2005 年 1 月 1 日以前的閲讀權限設高.
update cdb_threads set readperm=100 where dateline<1104537600 and digest=0
批量替換帖子裏面的評分者的用户名
update cdb_ratelog set uid = '新 uid', username = '新 username' where uid = '舊的 uid';
所有的附件默認閲讀權限為 1
update cdb_attachments set readperm=1
統計發帖量大約 0 的所有用户積分 1 的總量
SELECT count(`extcredits1`) FROM `cdb_members` where `posts`=0
批量修改 uid1~6 會員的 showemail 為 1
UPDATE `cdb_members` SET `showemail` ='1' WHERE `uid` in(1,2,3,4,5,6);
將主題 tid 大於 14651 的所有主題減去 16761780
update cdb_threads set tid=tid-16761780 where tid>14651;
update cdb_posts set tid=tid-16761780 where tid>14651;
update cdb_attachments set tid=tid-16761780 where tid>14651;
update cdb_myposts set tid=tid-16761780 where tid>14651;
update cdb_activities set tid=tid-16761780 where tid>14651;
update cdb_activityapplies set tid=tid-16761780 where tid>14651;
update cdb_favorites set tid=tid-16761780 where tid>14651;
update cdb_mythreads set tid=tid-16761780 where tid>14651;
update cdb_paymentlog set tid=tid-16761780 where tid>14651;
update cdb_polloptions set tid=tid-16761780 where tid>14651;
update cdb_polls set tid=tid-16761780 where tid>14651;
update cdb_pushedthreads set tid=tid-16761780 where tid>14651;
update cdb_relatedthreads set tid=tid-16761780 where tid>14651;
update cdb_rewardlog set tid=tid-16761780 where tid>14651;
update cdb_rsscaches set tid=tid-16761780 where tid>14651;
update cdb_sessions set tid=tid-16761780 where tid>14651;
update cdb_subscriptions set tid=tid-16761780 where tid>14651;
update cdb_threadsmod set tid=tid-16761780 where tid>14651;
update cdb_tradelog set tid=tid-16761780 where tid>14651;
update cdb_trades set tid=tid-16761780 where tid>14651;
此操作前請注意網站備份!!(按照 5.0 數據表進行修改的 6.0 的需要查看下數據庫對比下)
將積分 1 加到積分 2 上 並清零積分 1 的 sql
update cdb_members set extcredits1=extcredits1+extcredits2;
update cdb_members set extcredits1='0';
把 300 天未登錄的 ID 移到某一特殊用户組
update cdb_members set adminid=-1,groupid=特殊用户組 ID where lastactivity< unix_timestamp()-300*24*3600
服務器上禁止 IP 訪問命令
iptables -I INPUT -p TCP -s 218.0.211.0/24 --dport 80 -j DROP
查一個 IP 有哪個會員登錄
select * from cdb_membsers where lastip="IP"
UPDATE cdb_posts p, cdb_attachments a SET p.attachment=1 WHERE p.pid=a.pid;
找回丟失附件的 sql 語句
更新昨日發貼數
昨日發貼數:
select count(*) from cdb_posts where dateline> 昨天 0 時的時間戳 and dateline< 今天 0 時的時間戳
更新昨日發貼數:
UPDATE `cdb_settings` SET `value` = '昨日發帖數 1428' WHERE `variable` ='historyposts' LIMIT 1 ;
把"新手上路"用户組下的所有會員轉換到另一個特殊的用户組
pl: 特殊用户組沒有關聯任何的管理組
update cdb_members set groupid=特殊用户組的 id where groupid=新手上路用户組的 id and adminid=0
刪除一個板塊的所有回覆
delete from cdb_posts where fid = '需要刪除回覆的版塊 id' and first = 0;
delete from cdb_forums where fid=23 limit 1;
刪除 fid23 的板塊
圈子 sgid 字段缺少 添加的 sql
ALTER TABLE cdb_threads ADD sgid mediumint(8) unsigned NOT NULL default '0'
update cdb_threads set replies=(select count(*) from cdb_posts where tid=47708) where tid=47708
更新 tid27708 主題的統計
關閉所有板塊的允許其它模塊共享
update cdb_forums set allowshare=0
UPDATE `cdb_memberfields` SET `sightml` = ' '
所有用户的簽名清空
UPDATE cdb_posts SET subject=REPLACE(subject,'#','樓');
批量替換帖子中的回覆* #的顯示為 *樓
刪除一個主題的所有回覆
delete from cdb_posts where tid = '需要刪除回覆的主題的 tid' and first = 0;
UPDATE `cdb_settings` SET `value` = '1' WHERE CONVERT( `variable` USING utf8 ) = 'thumbstatus' LIMIT 1 ;
設置縮略圖為 為圖片附件添加縮略圖
UPDATE `cdb_settings` SET `value` = '2' WHERE CONVERT( `variable` USING utf8 ) = 'thumbstatus' LIMIT 1 ;
設置縮略圖為 將圖片附件縮到指定的大小
批量驗證所有未驗證的會員
UPDATE `cdb_members` SET `groupid` = '10' WHERE groupid='8';
批量刪除遊客回帖和主題
delete from cdb_threads where authorid=0;
delete from cdb_posts where authorid=0;
刪除在 180 天之前的全部短消息
delete from cdb_pms where dateline<1190518730
清空某個用户的已發短消息
update cdb_pms set delstatus=1 where msgfromid=發送者 ID
所有用户組 (包括系統用户組,普通用户組,特殊用户組) 都可以參與投票的 SQL 語句:
update cdb_usergroups set allowvote=1 where groupid<4 or groupid>9
UPDATE `cdb_usergroups` SET `raterange` = '1 -1 1 100
2 -1 1 100'
開啓所有用户組的擴展積分 1 和 2 的評分值為 最小-1 最大 1 24 小時 100
圖片附件設置正確 但是不直接顯示的調整 sql:
update cdb_attachments set `isimage` =1 where SUBSTRING(`filename`,-3,3)='jpg' or SUBSTRING(`filename`,-3,3)='gif'
固定天數內一部份附件到遠程附件的 sql
update cdb_attachments set remote = '1' where dateline<unix_timestamp()-86400*天數
修改所有用户組評分的 SQL 語句
update `cdb_usergroups` set `raterange`='擴展積分 ID 評分最小值 評分最大值 24 小時最大評分數
擴展積分 ID 評分最小值 評分最大值 24 小時最大評分數'
將主題 tid 大於 4009 的所有主題減去 16773200
update cdb_activities set tid=tid-16773200 where tid>4009;
update cdb_activityapplies set tid=tid-16773200 where tid>4009;
update cdb_attachments set tid=tid-16773200 where tid>4009;
update cdb_campaigns set tid=tid-16773200 where tid>4009;
update cdb_debateposts set tid=tid-16773200 where tid>4009;
update cdb_debates set tid=tid-16773200 where tid>4009;
update cdb_favorites set tid=tid-16773200 where tid>4009;
update cdb_forumrecommend set tid=tid-16773200 where tid>4009;
update cdb_myposts set tid=tid-16773200 where tid>4009;
update cdb_mythreads set tid=tid-16773200 where tid>4009;
update cdb_paymentlog set tid=tid-16773200 where tid>4009;
update cdb_polloptions set tid=tid-16773200 where tid>4009;
update cdb_polls set tid=tid-16773200 where tid>4009;
update cdb_posts set tid=tid-16773200 where tid>4009;
update cdb_relatedthreads set tid=tid-16773200 where tid>4009;
update cdb_rewardlog set tid=tid-16773200 where tid>4009;
update cdb_rsscaches set tid=tid-16773200 where tid>4009;
update cdb_sessions set tid=tid-16773200 where tid>4009;
update cdb_subscriptions set tid=tid-16773200 where tid>4009;
update cdb_threads set tid=tid-16773200 where tid>4009;
update cdb_threadsmod set tid=tid-16773200 where tid>4009;
update cdb_threadtags set tid=tid-16773200 where tid>4009;
update cdb_tradelog set tid=tid-16773200 where tid>4009;
update cdb_trades set tid=tid-16773200 where tid>4009;
update cdb_typeoptionvars set tid=tid-16773200 where tid>4009;
update cdb_videos set tid=tid-16773200 where tid>4009;
update cdb_videotags set tid=tid-16773200 where tid>4009;
如果安裝了 supesite 有了推送主題表還加上:
update cdb_pushedthreads set tid=tid-16773200 where tid>4009;
以上 sql 為 6.0 版本
批量替換論壇標題內容
UPDATE `cdb_threads` SET `subject` = replace (`subject`,'需要替換的','替換後的')
UPDATE `cdb_attachments` SET `thumb` = '0'
取消所有附件的縮略圖數據
UPDATE `cdb_threads` SET `highlight` = '0'
取消全部帖子的高亮顯示
論壇裏所有回覆長度小於 20 的而且沒有附件的貼子全部刪除掉
delete from cdb_posts where length(message)<20 and attachment=0
查詢 ftp 上的附件是否在數據庫內
phpmyadmin 中 執行 sql:
select * from cdb_attachments where attachment like "% 文件名稱%"
一次性給一個貼內的所有回帖人加積分
update cdb_members set extcredits2=extcredits2+10 where uid in(SELECT authorid FROM `cdb_posts` WHERE tid=主題 ID)
extcredits2 是需要增加的積分字段 , 使用的時候要注意增加的哪個積分字段
truncate cdb_validating
清空用户審核數據表
UPDATE `cdb_members` SET `oltime` = '0'
所有用户的在線時間修改為 0
把體積大於 819200kb 的附件指定為遠程附件
update cdb_attachments set remote = '1' WHERE filesize > 819200
ALTER TABLE `cdb_threads` CHANGE `tid` `tid` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT;