无法在 MySQL 5.6 中创建用户

Can't create user in MySQL 5.6

我想创建一个用户,它将成为我的 classicmodels 数据库中的管理员。我希望我的管理员用户可以创建其他用户帐户并将它们仅分配给 classicmodels 数据库。我已经完成了以下步骤:

  1. 以 root 身份登录
  2. create user admin@'%' identified by 'qwerty';
  3. grant all privileges on classicmodels.* to admin@'%' with grant option;
  4. flush privileges;
  5. show grants for admin@'%':
  6. 的结果

*.* 上授予使用密码 'admin'@'%' 的权限
GRANT ALL PRIVILEGES ON classicmodels.* TO 'admin'@'%' WITH GRANT OPTION

现在以管理员身份登录:

  1. use classicmodels;
  2. create user user1@'%' identified by 'qwerty';

    ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation

我没看出来,我哪里做错了。当我以 root 身份登录时,我在第 3 步中将所有权限授予了 admin。提前致谢。

您已在特定而非全局范围内授予数据库(模式)的所有权限。

运行下面查询并查看结果。

SELECT * FROM `mysql`.`db` WHERE `User` = 'admin' AND `Host` = '%';
SELECT * FROM `mysql`.`user` WHERE `User` = 'admin' AND `Host` = '%';

13.7.1.2 CREATE USER Syntax

...

... To use this statement, you must have the global CREATE USER privilege or the INSERT privilege for the mysql database. ...

...

更新

13.7.1.4 GRANT Syntax

...

The CREATE TABLESPACE, CREATE USER, FILE, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SHOW DATABASES, SHUTDOWN, and SUPER privileges are administrative and can only be granted globally.

...

您需要执行以下操作:

  1. 以 root 身份登录
  2. GRANT CREATE USER ON *.* TO 'admin'@'%';
  3. FLUSH PRIVILEGES;
mysql> SHOW GRANTS FOR 'admin'@'%';
+------------------------------------------------------------------------------------------------------------+
| Grants for admin@%                                                                                         |
+------------------------------------------------------------------------------------------------------------+
| GRANT CREATE USER ON *.* TO 'admin'@'%' IDENTIFIED BY PASSWORD '*AA1420F182E88B9E5F874F6FBE7459291E8F4601' |
| GRANT ALL PRIVILEGES ON `classicmodels`.* TO 'admin'@'%' WITH GRANT OPTION                                 |
+------------------------------------------------------------------------------------------------------------+
2 rows in set (0,00 sec)