开发者

Allowing a MySQL user to grant themselves privileges to a new database

开发者 https://www.devze.com 2023-03-27 03:46 出处:网络
I have a MySQL user, which we\'ll call Tom. Tom has global CREATE and SHOW DATABASES privileges, with the \'GRANT\' option.

I have a MySQL user, which we'll call Tom. Tom has global CREATE and SHOW DATABASES privileges, with the 'GRANT' option. The user 开发者_JAVA百科is assigned SELECT, INSERT, UPDATE and DELETE privileges on a per-database basis. However, after Tom creates a new database, he can't set his SELECT etc. privileges, despite having a global GRANT option. The error is (predictably) :

CREATE DATABASE `my_new_db`; -- this is fine
GRANT SELECT , INSERT , UPDATE , DELETE ON `my_new_db` . * TO 'Tom'@'%';
*Access denied for user 'Tom'@'%' to database 'my_new_db'*

This is being done via PHP, but I doubt that makes much difference.

Someone tell me what I'm doing wrong! Ta =]


You can't grant privileges you don't have. Tom needs to have global SELECT, INSERT, UPDATE, and DELETE privileges in order to grant them to others.


You are doing correctly. It's by design. However what you can do is written in the Reference Manual: "MySQL enables you to grant privileges on databases or tables that do not exist. For tables, the privileges to be granted must include the CREATE privilege. This behavior is by design, and is intended to enable the database administrator to prepare user accounts and privileges for databases or tables that are to be created at a later time."

http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-privileges

0

精彩评论

暂无评论...
验证码 换一张
取 消