找回密码
 注册
查看: 2490|回复: 0
收起左侧

[分享] Discuz论坛 常用SQL语句大全分享

[复制链接]

5342

主题

8363

帖子

1万

积分

管理员

出售国内外虚拟空间

Rank: 10Rank: 10Rank: 10

积分
14736
帖子
8363
精华
67
体力
14736 点
蓝豆
2391 点
注册时间
2007-6-8

终身成就奖LY官方团队会员身份ID卡

发表于 2010-8-15 00:46:20 | 显示全部楼层 |阅读模式
  1. -------------------常用SQL语句,请备份好再用,基本无错---------------------------------

  2. UPDATE `cdb_forums` SET `allowpostspecial` = '31'

  3. 所有板块的特殊主题开启

  4. 调整某个帖子的点击数
  5. UPDATE cdb_threads SET views=点击数 WHERE tid=主题编号;

  6. UPDATE `cdb_forums` SET `allowmediacode` = '1'
  7. 所有板块开启media代码



  8. update cdb_settings set value = 120 WHERE variable = 'maxavatarpixel'
  9. 调整所有用户最大头像尺寸(像素)为120



  10. UPDATE `cdb_threads` SET `closed` = '1' WHERE `fid` =20 ;
  11. 一次性关闭板块fid20帖子



  12. 把发帖数为0的用户都转到某个用户组

  13. update cdb_members set groupid = * where posts = 0;



  14. UPDATE `cdb_usergroups` SET `allowinvite` = '1', `inviteprice` = '价格';
  15. 开启全部用户组的邀请注册权限 并设置价格



  16. replace INTO cdb_settings VALUES ('watermarktype','0');
  17. 去除水印图片类型



  18. update cdb_members set lastpost='1186675200';
  19. 调整用户最后登录时间为 2007年8月10日


  20. UPDATE `cdb_forums` SET `status` = '1',
  21. `lastpost` = '' WHERE `fid` =6 LIMIT 1 ;

  22. 调整 板块隐藏的sql!



  23. 完整关闭supesite的sql语句:

  24. UPDATE `cdb_settings` SET `value` = '' WHERE `variable` = 'supe_siteurl' ;
  25. UPDATE `cdb_settings` SET `value` = '' WHERE `variable` = 'supe_sitename';
  26. UPDATE `cdb_settings` SET `value` = '0' WHERE `variable` = 'supe_status';
  27. UPDATE `cdb_settings` SET `value` = '' WHERE `variable` = 'supe_tablepre';
  28. UPDATE `cdb_settings` SET `value` = '0' WHERE `variable` = 'supe_circlestatus';



  29. 将A板块的所有帖子转到B板块的C分类里
  30. update cdb_threads set fid=B板块ID,typeid=c分类的ID where fid=A板块ID;
  31. update cdb_posts set fid=B板块ID where fid=A板块ID;

  32. 执行前备份一下数据库



  33. 去除后台管理员ip登录限制
  34. UPDATE `cdb_settings` SET `value` = '' WHERE CONVERT( `variable` USING utf8 ) ='adminipaccess' LIMIT 1 ;




  35. 删除风格5
  36. delete from cdb_styles where styleid=5 limit 1;




  37. UPDATE `cdb_members` SET `pmsound` = '1'
  38. 论坛所有用户短消息提示音修改为提示音1




  39. delete from cdb_usergroups where groupid = 0
  40. 删除groupid = 0的用户组




  41. UPDATE `cdb_forums` SET `alloweditpost` = '1'
  42. 所有板块开启允许编辑帖子

  43. 论坛后台 解除insenz绑定语句

  44. delete from cdb_settings where variable='insenz'

  45. 论坛后台执行后 就可以 重新注册和绑定了




  46. 关闭游客浏览所有版块的语句

  47. 可以这样构造SQL语句
  48. update cdb_forumfields set viewperm ='\t允许浏览的用户组的ID\t' where fid in(论坛板块ID)

  49. 如:

  50. update cdb_forumfields set viewperm ='\t1\t2\t' where fid in(1,2)



  51. UPDATE `cdb_forumfields` SET `rules` = '板块规则'
  52. 所有板块的板块规则设置~!




  53. UPDATE `cdb_forums` SET `jammer` = '1'
  54. 开启所有板块的干扰码




  55. 开启所有会员组邀请注册的权限
  56. UPDATE cdb_usergroups SET allowinvite=1, allowmailinvite=1, maxinvitenum=10, maxinviteday=15, inviteprice=10;

  57. //allowinvite 允许使用邀请注册:
  58. //allowmailinvite 允许发送邀请注册:
  59. //maxinvitenum 24小时内购买邀请码最大数量:
  60. //maxinviteday 邀请码有效期:
  61. //inviteprice 邀请码购买价格:



  62. 修改最高日发帖数

  63. UPDATE `cdb_settings` SET `value` = '昨日发帖数 最高日发帖数' WHERE `variable` ='historyposts' LIMIT 1 ;

  64. 昨日发帖数 和 最高日发帖数 修改为你需要的数字即可, 升级完sql后,更新缓存


  65. '昨日发帖数 最高日发帖数' 中间的空格是tab键~!



  66. UPDATE `cdb_settings` SET `value` = '0' WHERE CONVERT( `variable` USING utf8 ) = 'gzipcompress' LIMIT 1 ;

  67. 关闭论坛的gzip设置!





  68. 批量对用户组禁言
  69. update cdb_members set adminid='-1', groupid='4' where groupid='?';

  70. delete from cdb_threads where authorid=0;
  71. delete from cdb_posts where authorid=0;




  72. 批量删除游客组的发帖和主题

  73. uid 2000~3000的会员全部积分清零
  74. 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;




  75. 指定范围内的审核主题通过审核

  76. update cdb_threads set displayorder=0 where tid > 最小的 tid and tid < 最大的 tid




  77. 指定范围内的审核帖子通过审核
  78. update cdb_posts set invisible = 0 where tid > 最小的tid and tid < 最大的 tid




  79. 批量删除未审核通过的帖子和主题
  80. delete from cdb_threads where displayorder=-2;
  81. delete from cdb_posts where invisible=-2;



  82. 批量关闭投票
  83. UPDATE cdb_threads SET closed = 1 WHERE special=1



  84. UPDATE `cdb_members` SET `secques` = ''
  85. 清空用户安全问答!




  86. 清空某个用户组的全部积分sql:

  87. 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;



  88. update cdb_usergroups set allowtransfer=0


  89. 关闭所有用户组的积分转账



  90. update cdb_threads set readperm=100 where dateline<1133300000

  91. 修改05年11月29日21点33份20秒 前的主题阅读权限100

  92. 其中1133300000 是unix时间戳 (以秒为单位) 代表 05年11月29日21点33份20秒
  93. readperm=100 代表阅读权限



  94. 把2005年1月1日以前的阅读权限设高.
  95. update cdb_threads set readperm=100 where dateline<1104537600 and digest=0




  96. 批量替换帖子里面的评分者的用户名
  97. update cdb_ratelog set uid = '新uid', username = '新username' where uid = '旧的 uid';




  98. 所有的附件默认阅读权限为1
  99. update cdb_attachments set readperm=1




  100. 统计发帖量大约0的所有用户积分1的总量
  101. SELECT count(`extcredits1`) FROM `cdb_members` where `posts`=0




  102. 批量修改uid1~6会员的 showemail 为 1
  103. UPDATE `cdb_members` SET `showemail` ='1' WHERE `uid` in(1,2,3,4,5,6);




  104. 将主题tid大于14651的所有主题减去16761780
  105. update cdb_threads set tid=tid-16761780 where tid>14651;
  106. update cdb_posts set tid=tid-16761780 where tid>14651;
  107. update cdb_attachments set tid=tid-16761780 where tid>14651;
  108. update cdb_myposts set tid=tid-16761780 where tid>14651;
  109. update cdb_activities set tid=tid-16761780 where tid>14651;
  110. update cdb_activityapplies set tid=tid-16761780 where tid>14651;
  111. update cdb_favorites set tid=tid-16761780 where tid>14651;
  112. update cdb_mythreads set tid=tid-16761780 where tid>14651;
  113. update cdb_paymentlog set tid=tid-16761780 where tid>14651;
  114. update cdb_polloptions set tid=tid-16761780 where tid>14651;
  115. update cdb_polls set tid=tid-16761780 where tid>14651;
  116. update cdb_pushedthreads set tid=tid-16761780 where tid>14651;
  117. update cdb_relatedthreads set tid=tid-16761780 where tid>14651;
  118. update cdb_rewardlog set tid=tid-16761780 where tid>14651;
  119. update cdb_rsscaches set tid=tid-16761780 where tid>14651;
  120. update cdb_sessions set tid=tid-16761780 where tid>14651;
  121. update cdb_subscriptions set tid=tid-16761780 where tid>14651;
  122. update cdb_threadsmod set tid=tid-16761780 where tid>14651;
  123. update cdb_tradelog set tid=tid-16761780 where tid>14651;
  124. update cdb_trades set tid=tid-16761780 where tid>14651;

  125. 此操作前请注意备份!!(按照5.0数据表进行修改的 6.0的需要查看下数据库对比下)




  126. 将积分1加到积分2上 并清零积分1的sql

  127. update cdb_members set extcredits1=extcredits1+extcredits2;
  128. update cdb_members set extcredits1='0';




  129. 把300天未登录的ID移到某一特殊用户组
  130. update cdb_members set adminid=-1,groupid=特殊用户组ID where lastactivity< unix_timestamp()-300*24*3600



  131. 服务器上禁止IP访问命令

  132. iptables -I INPUT -p TCP -s 218.0.211.0/24 --dport 80 -j DROP




  133. 查一个IP有哪个会员登录

  134. select * from cdb_membsers where lastip="IP"




  135. UPDATE cdb_posts p, cdb_attachments a SET p.attachment=1 WHERE p.pid=a.pid;
  136. 找回丢失附件的sql语句





  137. 更新昨日发贴数

  138. 昨日发贴数:
  139. select count(*) from cdb_posts where dateline>昨天0时的时间戳 and dateline<今天0时的时间戳
  140. 更新昨日发贴数:
  141. UPDATE `cdb_settings` SET `value` = '昨日发帖数\t1428' WHERE `variable` ='historyposts' LIMIT 1 ;




  142. 把"新手上路"用户组下的所有会员转换到另一个特殊的用户组

  143. pl:特殊用户组没有关联任何的管理组

  144. update cdb_members set groupid=特殊用户组的id where groupid=新手上路用户组的id and adminid=0




  145. 删除一个板块的所有回复
  146. delete from cdb_posts where fid = '需要删除回复的版块id' and first = 0;




  147. delete from cdb_forums where fid=23 limit 1;
  148. 删除fid23的板块




  149. 圈子sgid字段缺少 添加的sql

  150. ALTER TABLE cdb_threads ADD sgid mediumint(8) unsigned NOT NULL default '0'




  151. update cdb_threads set replies=(select count(*) from cdb_posts where tid=47708) where tid=47708

  152. 更新tid27708主题的统计




  153. 关闭所有板块的允许其它模块共享
  154. update cdb_forums set allowshare=0





  155. UPDATE `cdb_memberfields` SET `sightml` = ' '

  156. 所有用户的签名清空





  157. UPDATE cdb_posts SET subject=REPLACE(subject,'#','楼');

  158. 批量替换帖子中的回复* #的显示为 *楼






  159. 删除一个主题的所有回复
  160. delete from cdb_posts where tid = '需要删除回复的主题的tid' and first = 0;






  161. UPDATE `cdb_settings` SET `value` = '1' WHERE CONVERT( `variable` USING utf8 ) = 'thumbstatus' LIMIT 1 ;
  162. 设置缩略图为 为图片附件添加缩略图


  163. UPDATE `cdb_settings` SET `value` = '2' WHERE CONVERT( `variable` USING utf8 ) = 'thumbstatus' LIMIT 1 ;
  164. 设置缩略图为 将图片附件缩到指定的大小





  165. 批量验证所有未验证的会员
  166. UPDATE `cdb_members` SET `groupid` = '10' WHERE groupid='8';





  167. 批量删除游客回帖和主题

  168. delete from cdb_threads where authorid=0;
  169. delete from cdb_posts where authorid=0;




  170. 删除在180天之前的全部短消息
  171. delete from cdb_pms where dateline<1190518730






  172. 清空某个用户的已发短消息

  173. update cdb_pms set delstatus=1 where msgfromid=发送者ID





  174. 所有用户组(包括系统用户组,普通用户组,特殊用户组)都可以参与投票的SQL语句:
  175. update cdb_usergroups set allowvote=1 where groupid<4 or groupid>9






  176. UPDATE `cdb_usergroups` SET `raterange` = '1\t-1\t1\t100\n2\t-1\t1\t100'
  177. 开启所有用户组的扩展积分1和2的评分值为 最小-1 最大1 24小时100






  178. 图片附件设置正确 但是不直接显示的调整sql:

  179. update cdb_attachments set `isimage` =1 where SUBSTRING(`filename`,-3,3)='jpg' or SUBSTRING(`filename`,-3,3)='gif'





  180. 固定天数内一部份附件到远程附件的sql
  181. update cdb_attachments set remote = '1' where dateline<unix_timestamp()-86400*天数




  182. 修改所有用户组评分的SQL语句

  183. update `cdb_usergroups` set `raterange`='扩展积分ID\t评分最小值\t评分最大值\t24小时最大评分数\n扩展积分ID\t评分最小值\t评分最大值\t24小时最大评分数'






  184. 将主题tid大于4009的所有主题减去16773200

  185. update cdb_activities set tid=tid-16773200 where tid>4009;
  186. update cdb_activityapplies set tid=tid-16773200 where tid>4009;
  187. update cdb_attachments set tid=tid-16773200 where tid>4009;
  188. update cdb_campaigns set tid=tid-16773200 where tid>4009;
  189. update cdb_debateposts set tid=tid-16773200 where tid>4009;
  190. update cdb_debates set tid=tid-16773200 where tid>4009;
  191. update cdb_favorites set tid=tid-16773200 where tid>4009;
  192. update cdb_forumrecommend set tid=tid-16773200 where tid>4009;
  193. update cdb_myposts set tid=tid-16773200 where tid>4009;
  194. update cdb_mythreads set tid=tid-16773200 where tid>4009;
  195. update cdb_paymentlog set tid=tid-16773200 where tid>4009;
  196. update cdb_polloptions set tid=tid-16773200 where tid>4009;
  197. update cdb_polls set tid=tid-16773200 where tid>4009;
  198. update cdb_posts set tid=tid-16773200 where tid>4009;
  199. update cdb_relatedthreads set tid=tid-16773200 where tid>4009;
  200. update cdb_rewardlog set tid=tid-16773200 where tid>4009;
  201. update cdb_rsscaches set tid=tid-16773200 where tid>4009;
  202. update cdb_sessions set tid=tid-16773200 where tid>4009;
  203. update cdb_subscriptions set tid=tid-16773200 where tid>4009;
  204. update cdb_threads set tid=tid-16773200 where tid>4009;
  205. update cdb_threadsmod set tid=tid-16773200 where tid>4009;
  206. update cdb_threadtags set tid=tid-16773200 where tid>4009;
  207. update cdb_tradelog set tid=tid-16773200 where tid>4009;
  208. update cdb_trades set tid=tid-16773200 where tid>4009;
  209. update cdb_typeoptionvars set tid=tid-16773200 where tid>4009;
  210. update cdb_videos set tid=tid-16773200 where tid>4009;
  211. update cdb_videotags set tid=tid-16773200 where tid>4009;

  212. 如果安装了supesite 有了推送主题表还加上:
  213. update cdb_pushedthreads set tid=tid-16773200 where tid>4009;

  214. 以上sql为6.0版本







  215. 批量替换论坛标题内容
  216. UPDATE `cdb_threads` SET `subject` = replace (`subject`,'需要替换的','替换后的')






  217. UPDATE `cdb_attachments` SET `thumb` = '0'
  218. 取消所有附件的缩略图数据




  219. UPDATE `cdb_threads` SET `highlight` = '0'
  220. 取消全部帖子的高亮显示





  221. 论坛里所有回复长度小于20的而且没有附件的贴子全部删除掉
  222. delete from cdb_posts where length(message)<20 and attachment=0




  223. 查询ftp上的附件是否在数据库内
  224. phpmyadmin中 执行sql:
  225. select * from cdb_attachments where attachment like "%文件名称%"




  226. 一次性给一个贴内的所有回帖人加积分
  227. update cdb_members set extcredits2=extcredits2+10 where uid in(SELECT authorid FROM `cdb_posts` WHERE tid=主题ID)

  228. extcredits2 是需要增加的积分字段 , 使用的时候要注意增加的哪个积分字段





  229. truncate cdb_validating
  230. 清空用户审核数据表






  231. UPDATE `cdb_members` SET `oltime` = '0'

  232. 所有用户的在线时间修改为0







  233. 把体积大于 819200kb的附件指定为远程附件
  234. update cdb_attachments set remote = '1' WHERE filesize > 819200



  235. ALTER TABLE `cdb_threads` CHANGE `tid` `tid` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT;
复制代码
出售国内或美国高性能虚拟空间,高速VPS以及服务器! 同时承接各种类型的网站制作,网站维护,支付宝交易安全放心!    联系QQ:6102031
懒得打字嘛,点击右侧快捷回复
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

网站公告上一条 /2 下一条

GMT+8, 2025-2-11 07:40 , Processed in 0.107712 second(s), 23 queries , Gzip On.

© 2006-2022 Powered by Discuz! X3.4

快速回复 返回顶部 返回列表