Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I "grant create user" as a non-root user?

Tags:

mysql

I have a database where I would like users to be able to create new users. That is achievable via GRANT CREATE USER as follows:

grant create user on *.* to foo;

This works great and foo can create users. My problem is that the line above works if run as root, but does not work if run as a normal user, even if such user already has the CREATE USER privilege.

In short, normal users cannot delegate the ability to create users. I have been searching far and wide for any particular privilege you need to be able to do this, and I'm beginning to think it's something that only root can do, although I have found no evidence of this in the MySQL documentation.

The question: how can I allow a normal user to let new users create users?

like image 868
Gigi Avatar asked Oct 06 '11 21:10

Gigi


2 Answers

Both answers were useful - I used a combination of both and it seems to have worked.

As root (admin is a normal user):

mysql> grant create user on *.* to admin with grant option;
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

As admin (remember, he's a normal user):

mysql> grant create user on *.* to foo with grant option;
Query OK, 0 rows affected (0.00 sec)

Thank you so much.

like image 119
Gigi Avatar answered Sep 27 '22 23:09

Gigi


-- Create username user

GRANT ALL PRIVILEGES ON `tshirtshop`.*
      TO 'username'@'localhost' IDENTIFIED BY 'password'
      WITH GRANT OPTION;
like image 27
Vincy Oommen Avatar answered Sep 28 '22 00:09

Vincy Oommen