33

Surprisingly, it's been tough for me to find the command(s) to do this. Does anyone know how to add a group? Thanks!

Or do something like this:

# create the MySQL group
dscl . create /Groups/mysql
# give it some group id
dscl . create /Groups/mysql gid 296
Tony
  • 1,241
  • 4
  • 17
  • 21

4 Answers4

32

"System preferences" -> "Users&Groups" -> "+" (as if you were adding new account) -> Under "New account" select "Group" -> Type in group name -> "Create group"

ishandutta2007
  • 153
  • 1
  • 6
rytis
  • 2,324
  • 1
  • 18
  • 13
24

I've used these to add dba group:

sudo dscl . -create /groups/dba
sudo dscl . -append /groups/dba gid 4200
sudo dscl . -append /groups/dba passwd "*"
MDMarra
  • 100,183
  • 32
  • 195
  • 326
Andrea Girardi
  • 356
  • 2
  • 6
  • 2
    Not sure if things have changed since this answer was written, but with El Capitan (v10.11), in order to get the group name to display in `ls -l` commands, I had to use a variation of the second command, `sudo dscl . -append /groups/dba PrimaryGroupID 4200` I got the field name from the output of `sudo dscl . -readall /groups`. – Greg Tarsa Oct 12 '16 at 03:51
  • ...and `passwd` is now `Password`. – bjnord Sep 10 '17 at 16:21
14

pulegium's answer is generally preferred, but if you want a command-line way:

sudo dseditgroup -o create mysql

(note that creating a group named mysql is probably a bad idea -- there's already a group named _mysql, with mysql as an alias.)

Gordon Davisson
  • 11,036
  • 3
  • 27
  • 33
  • "pulegium's answer" is apparently no longer available. Do you remember what it was? – Codie CodeMonkey May 19 '12 at 12:17
  • IIRC it was to use System Preferences -- a lot like rytis' answer. (@rytis: did you change your username, by any chance?) – Gordon Davisson May 19 '12 at 15:25
  • 1
    In my opinion, this is the most stable answer for creating a group on Mac OSX. In testing a solution for my latest product ([xcron](https://github.com/cubiclesoft/xcron)), I found that `dseditgroup` appears to produce the most consistent results a decade later while `dscl` has undergone inconsistent changes over the same time period. – CubicleSoft Feb 23 '22 at 00:45
8

As Gordon Davisson notes, standard Mac OS X 10.6 already has a mysql group, as this command shows:

dscl . -read /Groups/mysql

You shouldn’t create your own mysql group, and any attempts to modify it will affect the _mysql group. But to answer your question, the most succinct way to do it would be this single command:

dscl . -create /Groups/mysql gid 296

To add an encrypted password to the group:

dscl . -passwd /Users/mysql ‘my secret’

Note: Andrea Girardi’s method creates a plaintext password, which isn’t so good.

Hawkeye
  • 81
  • 1
  • 1