How can I restrict a MySQL user to a particular tables

╄→гoц情女王★ 提交于 2019-11-26 20:11:53

问题


How can I restrict a user_account in MySQL database to a particular tables. Ex:

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.


回答1:


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.

Afterwards, remember to flush the privileges to they become effective.

FLUSH PRIVILEGES;



回答2:


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.

You cannot grant access to individual tables which do not exist yet without granting access to all tables.



来源:https://stackoverflow.com/questions/9780637/how-can-i-restrict-a-mysql-user-to-a-particular-tables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!