[英]How to grant only few previleges ( to execute only DML and DDL statements) to the new user in MySQL?
How to grant only few previleges ( to execute only DML and DDL statements) to the new user in MySQL ?如何在 MySQL 中仅向新用户授予少数特权(仅执行 DML 和 DDL 语句)?
I tried the below command :我尝试了以下命令:
GRANT CREATE, ALTER, DROP, SELECT, INSERT, UPDATE, DELETE ON database.* to 'karthik' identified by 'shimoga';
But, it is showing Syntax error.但是,它显示语法错误。
You need to take out identified by 'shimoga' from your statement.您需要从您的声明中删除“shimoga”标识。
CREATE USER:创建用户:
CREATE USER 'karthik'@'instance' IDENTIFIED BY 'Password';
THEN GRANT Privileges:然后授予特权:
GRANT SELECT, DELETE, UPDATE, EXECUTE, INSERT, DROP, ALTER, CREATE ON databaseName.* TO 'karthik'@'instancename';
Better Solution will be to create a Role.更好的解决方案是创建一个角色。 And assign the role to user.并将角色分配给用户。 This will make your job easier if you have many users that needs similar privileges.如果您有许多需要类似权限的用户,这将使您的工作更轻松。
First Create a Role:首先创建一个角色:
CREATE ROLE IF NOT EXISTS 'Developer'@'localhost';
Then Assign the required Privileges to the Role.然后将所需的权限分配给角色。
GRANT SELECT, DELETE, UPDATE, EXECUTE, INSERT, DROP, ALTER ON databaseName.* TO 'Developer'@'instanceName';
Finally Assign the Role to User which you would have already created:最后将角色分配给您已经创建的用户:
GRANT 'Developer'@'localhost' TO 'karthik'@'instanceName';
SET DEFAULT ROLE ALL TO 'karthik'@'instanceName';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.