How can I restrict a MySQL user to a particular tables

前端 未结 2 1687
迷失自我
迷失自我 2020-12-05 10:39

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

UserName: RestrictedUser
DatabaseName: db_Payroll 
TableName: 
  tb_Employee         


        
2条回答
  •  旧巷少年郎
    2020-12-05 11:10

    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 so they become effective by running

    FLUSH PRIVILEGES;
    

提交回复
热议问题