Is it possible to run an sql query in mysql that'll place specified users into a specified secondary user group?
for example, say I want John, Joe, and Mary in the secondary group called mailer. can this be accomplished through mysql?
after I run that and do what I need to do, can I then run another query to remove the same users from the secondary user group they were previously placed in?!
Run the below query in PHPMyAdmin:
UPDATE mybb_users SET usergroup=X WHERE usergroup=Y
Just saw you want for additional usergroups, the above query would move MAIN USERGROUP, if you want additional, please refer to Ranjani's query.
X is the GID of the usergroup you want to move them into and Y is the GID of their original usergroup.
Replace
mybb in query if you have some other table prefix in database tables. (by default, it is mybb_users and so on)
UPDATE `mybb_users` SET `additionalgroups` = X WHERE `username` = '[username]';
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = '[username]';
OR
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `additionalgroups` = X;
see also :
this code ; {make new file with care }
(2011-10-04, 05:37 AM)ranjani Wrote: [ -> ]UPDATE `mybb_users` SET `additionalgroups` = X WHERE `username` = '[username]';
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = '[username]';
OR
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `additionalgroups` = X;
see also : this code ; {make new file with care }
huh, neither of the first two are working right. I ran these queries to try and remove the current 2nd user group my user was in as the code shows here:
UPDATE `mybb_users` SET `additionalgroups` = 0 WHERE `username` = '[my username]';
UPDATE `mybb_users` SET `additionalgroups` = '0' WHERE `username` = '[my username]';
Try:
UPDATE mybb_users
SET additionalgroups
= NULL WHERE username
= '[my username]';
(2011-10-04, 01:56 PM)PJGIH Wrote: [ -> ]Try:
UPDATE mybb_users
SET additionalgroups
= NULL WHERE username
= '[my username]';
assuming the only thing I was supposed to change was [my username], then no, it didn't work either. my username still has an additional user group.
Whoops, you're right.
This should work.
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = '[my username]';
(2011-10-04, 02:33 PM)PJGIH Wrote: [ -> ]Whoops, you're right.
This should work.
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = '[my username]';
nope, still not.
I tried it on two usernames now.
this is the query I ran:
UPDATE `mybb_users` SET `additionalgroups` = '8' WHERE `username` = '[andrewjs18]';
note, I tried your code where
additionalgroups
was left blank, but it didn't do anything, so I tried adding in a user group to see if it would move it, and it didn't.
Don't use brackets around the username.
e.g.
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = 'PJGIH';
(2011-10-04, 02:49 PM)PJGIH Wrote: [ -> ]Don't use brackets around the username.
e.g.
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = 'PJGIH';
perfect, that worked! geez, if I just tried that originally, it would of work. now that that is worked out, when I want to do more than 1 username at once, would I write it like this?
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = 'guy','guy2','guy3';