解决mysql中 you are not allowed to create user with grant 的问题
先查看一下错误------
>
mysql> grant select,insert on company.* to 'username'@'localhost' with grant opt
ion ;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant select,insert on company.* to 'username'@'localhost' with grant opt
ion ;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
排查原因–
1,查看root用户是否有grant_priv 权限,
mysql> select user ,grant_priv from user ;
+------------------+------------+
| user | grant_priv |
+------------------+------------+
| mysql | Y |
| root | Y |
| huixin | N |
| mysql.infoschema | N |
| mysql.session | N |
| mysql.sys | N |
| username | N |
+------------------+------------+
7 rows in set (0.00 sec)
发现有该权限,这说明不是权限的问题;继续排查下一个–
2,如果root用户仅在 localhost主机下去授权用户在别的主机上的权限也是不可以的,比如 ‘root’@'localhost’ 去授权别的主机用户 ‘username’@‘otherhost’ 也会报错,所以修改root用户的 host 为可以访问所有主机(打造一个真正的超级管理员),然后更新权限为拥有所有的权限,这里是必须要更新的,要不然还会报错,(对于为何要再次更新权限,我是这样理解的,只要更改了 user,host,或者authentication_string中的任何一个就要刷新权限)(对于为何要重新给 修改后的root用户重新赋予权限)因为没有刷新之前的记录的话新的权限没有覆盖
mysql> update user set host='%' where user='root' ;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> grant all privileges on *.* to 'root'@'%' ;
Query OK, 0 rows affected (0.00 sec)
3,刷新权限,授予权限
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> grant select ,insert ,update on company.* to 'huixin_user'@'localhost' wi
th grant option ;#8.0之后的mysql不支持 授权的时候就进行用户创建,所以创建 之后才能授权;
ERROR 1410 (42000): You are not allowed to create a user with GRANT
mysql> grant select ,insert ,update on company.* to 'huixin'@'localhost' with gr
ant option ;
Query OK, 0 rows affected (0.00 sec)
由于huixin用户是之前创建好的,授权的时候又给他授权了grant_priv ,再次查看huiixn的权限
mysql> select user ,host,select_priv,insert_priv,update_priv,grant_priv from user where user='huiixn';
+------------------+-----------+-------------+-------------+-------------+------------+
| user | host | select_priv | insert_priv | update_priv | grant_priv |
+------------------+-----------+-------------+-------------+-------------+------------+
| |
| huixin | localhost | Y | Y | Y | N |
| |
+------------------+-----------+-------------+-------------+-------------+------------+
7 rows in set (0.00 sec)
mysql>
以上就是解决的具体方式,整体思路如下:
登录root用户,
进入mysql数据库,
修改root 的主机名为可以访问所有主机,
重新更新root的所有权限
刷新权限
创建用户(如果之前创建过则不用再次创建)
授权给用户