如何将 MySQL 用户限制为特定表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9780637/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I restrict a MySQL user to a particular tables
提问by aintgel
How can I restrict a user_account in MySQL database to a particular tables. Ex:
如何将 MySQL 数据库中的 user_account 限制为特定表。前任:
UserName: RestrictedUser
DatabaseName: db_Payroll
TableName:
tb_Employees
tb_Users
tb_Payroll_YYMMDD
tb_Payroll_Processed
I want to restrict "RestrictedUser" to tb_Users
and tb_Employees
only and the rest of the tables of db_Payroll
that will be created for future use is granted to have access.
我想将“RestrictedUser”限制为tb_Users
并且tb_Employees
仅,并且db_Payroll
将创建以供将来使用的其余表被授予访问权限。
回答by kba
Assuming the user has no current privileges, you can do the following
假设用户当前没有权限,可以执行以下操作
GRANT SELECT, INSERT, DELETE ON db_Payroll.tb_Users TO RestrictedUser@'%'
GRANT SELECT, INSERT, DELETE ON db_Payroll.tb_Employees TO RestrictedUser@'%'
Depending on exactly which privileges you wish to grant the user, you can change SELECT, INSERT, DELETE
to something else, e.g. ALL PRIVILEGES
.
根据您希望授予用户的确切权限,您可以更改SELECT, INSERT, DELETE
为其他内容,例如ALL PRIVILEGES
.
Afterwards, remember to flush the privileges to they become effective.
之后,请记住刷新权限以使其生效。
FLUSH PRIVILEGES;
回答by duskwuff -inactive-
You can grant access to individual tables by running:
您可以通过运行以下命令授予对单个表的访问权限:
GRANT ALL ON db_Payroll.tb_Users to RestrictedUser@RestrictedHostName;
And similarly for other tables. Use a list of operations instead of ALL
if appropriate.
其他表也类似。ALL
如果合适,请使用操作列表代替。
You cannot grant access to individual tables which do not exist yet without granting access to all tables.
您不能在不授予对所有表的访问权限的情况下授予对尚不存在的单个表的访问权限。