简体   繁体   English

无法在 mysql 8.0.17 上授予选择

[英]Cannot Grant select on mysql 8.0.17

I want to grant select privilege to user from every host, but getting an error, you're not allow to create a user我想向每个主机的用户授予选择权限,但出现错误,您不允许创建用户

mysql> GRANT SELECT ON *.* TO 'alice'@'%' WITH GRANT OPTION; mysql> GRANT SELECT ON *.* TO 'alice'@'%' WITH GRANT OPTION;

ERROR 1410 (42000): You are not allowed to create a user with GRANT ERROR 1410 (42000): 您不能使用 GRANT 创建用户

I don't want to create a new user, for that I used command CREATE USER我不想创建新用户,因为我使用了命令 CREATE USER

I tried to create a new user but the grant command also failed.我试图创建一个新用户,但授权命令也失败了。

A good idea (and a good practice) in this MySql Version (8 and above) is to config ROLES and then set the users for it, like this good article (read it, is very good!).在这个 MySql 版本(8 及以上)中,一个好主意(也是一个好实践)是配置 ROLES,然后为其设置用户,就像这篇好文章(阅读它,非常好!)。

You'll can set your role to many users.您可以将您的角色设置为多个用户。

Something like this:像这样的东西:

1 - Create the role: 1 - 创建角色:

create ROLE name_of_your_role;

2 - Set the necessary privileges to the ROLE, and remember, in this MySql version you dont need of Flush Privileges . 2 - 为 ROLE 设置必要的权限,记住,在这个 MySql 版本中你不需要 Flush Privileges Example ( change mydatabase expression for your database name or wildcard, like you need):示例(根据需要更改数据库名称或通配符的 mydatabase 表达式):

grant alter,create,delete,drop,index,insert,select,update,trigger,alter
 routine,create routine, execute, create temporary tables 
on mydatabase.* to 'name_of_your_role';

3 - Grant the role for your user: 3 - 为您的用户授予角色:

grant 'name_of_your_role' to 'alice';

4 - Set this role as default to your user: 4 - 将此角色设置为您的用户的默认角色:

set default role 'name_of_your_role' to 'alice';

I just had the same issue.我只是有同样的问题。

But my problem was that I made a mistake in CREATE USER query.但我的问题是我在CREATE USER查询中犯了一个错误。 I wanted to create grafana user, but executed the following query: CREATE USER grafan IDENTIFIED BY '<password>';我想创建grafana用户,但执行了以下查询: CREATE USER grafan IDENTIFIED BY '<password>'; (Note that I created grafan user here instead of grafana ) (请注意,我在这里创建了grafan用户而不是grafana

Then, when I executed query GRANT SELECT ON mydb.* TO grafana@'%';然后,当我执行查询GRANT SELECT ON mydb.* TO grafana@'%'; I got an error ERROR 1410 (42000): You are not allowed to create a user with GRANT .我收到错误ERROR 1410 (42000): You are not allowed to create a user with GRANT There was no mention that user grafana does not exist.没有提到用户grafana不存在。

I spent about 20 minutes to figure out what I was doing wrong.我花了大约 20 分钟来弄清楚我做错了什么。

So if you are reading this, just check that you had correctly created your user.因此,如果您正在阅读本文,只需检查您是否正确创建了用户。 Hope this will help someone.希望这会对某人有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM