Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 07-24-2017, 10:18 PM
GHRake GHRake is offline
 
Join Date: Sep 2015
Location: USA
Posts: 46
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Useful SQL Queries

Here is just a list of useful mysql queries I've saved over the years and I thought others might find them useful as well. Warning: If you aren't experienced with SQL and modifying databases you must be extremely careful what you do and always make a backup first.

PHP Code:
#Remove logged IP Addresses for a certain userid
UPDATE ipdata set ip='' WHERE userid 123456;
UPDATE ipdata set altip='' WHERE userid 123456;
UPDATE post set ipaddress='' WHERE userid 123456;

#Force password reset on next login for all users
update user set passworddate='2000-01-01';
update usergroup set passwordexpires '3650';

#Migrated or upgraded vBulletin and some users dont have updated stronger password salts/hashes?
#Find those users with short Password salts:
SELECT useridusernamePASSWORD salt FROM  user WHERE length(salt) < 10;

#Force users with less secure salts to reset password and update encryption on next login:
update user set passworddate='2000-01-01' WHERE length(salt) < 10;
update usergroup set passwordexpires '3650';

#Find users that havent updated their passwords since the above query
#Use this to keep track of how many people have updated:
#Best solution would be to create a seperate usergroup, move them into it and then
#Move them out when theyve changed their password
select useridusernamepassworddate from user where passworddate '2000-01-01';

#Find users that havent signed in recently:
select useridusernamelastvisit from user where lastvisit UNIX_TIMESTAMP('2017-01-01')

#Alternatively find users that have signed in recently:
select useridusernamelastvisit from user where lastvisit UNIX_TIMESTAMP('2017-01-01')

#Unsubscribe all users from all threads:
truncate subscribethread;

#Find all posts containing certain text:
SELECT *  FROM post WHERE pagetext LIKE '%viagra%'

#Replace text in all posts:
UPDATE post SET pagetext replace(pagetext'Microsoft''MicroShit');

#Board migration left lots of "&quot;" all over your forum? 
#This is how you change &quot; to the quote thingy in all posts:
UPDATE post SET pagetext replace(pagetext'&quot;''"');

#Replace all old quote tags with correct vbulletin quote tags:
SELECT *  FROM post WHERE pagetext LIKE '%[quote author=%'
UPDATE post SET pagetext replace(pagetext'quote author''quote');

#Find all attachments by specific user:
SELECT *  FROM attachment WHERE userid 3746;

#Remove and disable thread ratings:
truncate threadrate;
UPDATE forum SET options options 2048 WHERE (options 2048)

#Select all threads from forum
SELECT FROM thread where forumid 41;

#Change thread prefix for all threads in forum:
UPDATE thread SET prefixid 'Help' WHERE forumid 41;

#Close all threads in a forum
UPDATE thread SET open '0' WHERE forumid 33;

#Recently enabled thread titles to propogate to all replies but want to make it retroactive?
#Make all post have same title as thread prepended with "re: "
UPDATE post
LEFT JOIN thread
ON post
.threadid thread.threadid
SET post
.title concat('Re: ',thread.title)
WHERE post.title '';

#Disable "Who Read This Thread" on all forums:
UPDATE forum SET options options 1048576 WHERE (options 1048576);

#Delete all soft deleted posts
delete from post where visible 2
And this one is a doozy. Some old imported posts include this whacky quote tag:
[quote author=Sleinzel link=topic=73.msg304#msg304 date=1337956060]

To replace them with vbulletin quote tags you run this query:
PHP Code:
update post set pagetext =
REPLACE(`pagetext`,TRIM(MID(`pagetext`,LOCATE('quote author=', `pagetext`),IF(LOCATE(' ',`pagetext`,LOCATE('date=',`pagetext`))>0,LOCATE(']',`pagetext`,LOCATE('date=',`pagetext`)+5),LOCATE('date=',`pagetext`)+15)-LOCATE('quote author=', `pagetext`))),TRIM(CONCAT('quote=',MID(SUBSTRING_INDEX(`pagetext`,'link=',1),LOCATE('quote author=', `pagetext`)+13))))
WHERE `pagetextREGEXP '\[quote author=[A-Za-z0-9 ]+ link=topic=[0-9]+.msg[0-9]+#msg[0-9]+ date=[0-9]+\]'
For the latest updates to my list you can visit my bitbucket snippet page
Reply With Quote
7 благодарности(ей) от:
creative-friend, Kane@airrifle, MarkFL, Rafa-el, Stratis, TheLastSuperman, unitedpunjab
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:28 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05063 seconds
  • Memory Usage 2,208KB
  • Queries Executed 13 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)post_thanks_box
  • (7)post_thanks_box_bit
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete