其他分享
首页 > 其他分享> > 关于 ERROR 1141 (42000): There is no such grant defined for user ‘xxx‘ on host ‘yyy‘ 的一种原因

关于 ERROR 1141 (42000): There is no such grant defined for user ‘xxx‘ on host ‘yyy‘ 的一种原因

作者:互联网

今天做了一个实验,
mysql> select * from tables_priv;
±----------±---------±------±-----------±---------------±--------------------±-----------±------------+
| Host | Db | User | Table_name | Grantor | Timestamp | Table_priv | Column_priv |
±----------±---------±------±-----------±---------------±--------------------±-----------±------------+
| localhost | schoolDB | zhang | Vjava | root@localhost | 2022-01-18 16:33:16 | Select | |
±----------±---------±------±-----------±---------------±--------------------±-----------±------------+
1 row in set (0.00 sec)

mysql> revoke select on schoolDB.Vjava from 'zhang'@'localhost';
ERROR 1141 (42000): There is no such grant defined for user ‘zhang’ on host ‘localhost’
出现错误提示,仔细确认了命令语句都正确,没有错别字,用户名user 和主机host 都拼写无误,
但仍报错,
ERROR 1141 (42000): There is no such grant defined for user ‘zhang’ on host ‘localhost’
这说明,这个user+host的组合出现了问题,

于是,迅速查询 user 表,如下,
mysql> select user,host from user;
±------±----------------------+
| user | host |
±------±----------------------+
| zhao | % |
| root | 127.0.0.1 |
| chen | 192.168.231.% |
| li | 192.168.231.% |
| root | 192.168.231.% |
| wang | 192.168.231.% |
| zhang | 192.168.231.% |
| root | localhost |
| root | localhost.localdomain |
±------±----------------------+
的确没有用户 ‘zhang’@‘localhost’,是之前把这个用户删除了,
所以,当revoke的时候就一直被拒绝,

想了一个解决方案,就是再重新建立这个用户,然后再去 revoke 回收权限,
于是,开始创建用户
mysql> create user 'zhang'@'localhost' ;
ERROR 1396 (HY000): Operation CREATE USER failed for ‘zhang’@‘localhost’
但报错,
经过网上查询,得知,

Assume the user is there, so drop the user
After deleting the user, there is need to flush the mysql privileges
Now create the user.

之前,drop user 删除此用户的时候,没有flush privileges 的原因,需要手工再次执行 drop user 并重新 flush privileges,
所以需要再 drop user 一遍,并刷新特权 flush privileges;

mysql> drop user 'zhang'@'localhost';
Query OK, 0 rows affected (0.00 sec)

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

在创建用户之前,又运行了一次,select * from tables_priv;,看到 随着 drop user 和flush privileges,
跟这个用户有关的 特权也一并被删除了。如下,
mysql> select * from tables_priv;
Empty set (0.00 sec)

所以,说,revoke 报错,和 create user 报错 ERROR 1141 (42000),
的根本原因是,在 drop user 的时候,没有进行 刷新特权的操作 即 flush privileges 导致的,
January the 28 th 2022 Friday

标签:1141,grant,zhang,no,flush,user,mysql,drop,localhost
来源: https://blog.csdn.net/m0_47505062/article/details/122726816