MySql:限制一张表中一列的更新权限

2022-01-15 00:00:00 mariadb mysql

我有一个表,我们称之为学生,在一个名为注册的模式中.表学生有一个名为地址的列,我不希望某个用户更新(其他权限很好,例如选择、插入).该表和该模式中的所有其他列都应具有更新权限.

I have a table, lets call it student, in a schema called enrollment. Table student has a column called address that I don't want a certain user to update (other permissions are fine such as select, insert). All other columns in that table AND in that schema should have the update privilege.

这可行吗?

推荐答案

可以设置数据库/表/列的权限.但我真的不会尝试在那个级别使用 MySQL 的权限机制.相反,我会编写应用程序代码来决定谁可以看到/更改什么.从长远来看,这更加灵活.并且对用户来说更优雅——而不是收到关于权限的神秘 MySQL 错误消息,UI 根本不会显示不应该显示的内容.对于更新,UI 甚至不会给用户选项.

You can set privileges on database / table / column. But I really would not try to use MySQL's privilege mechanism at that level. I would instead write application code to decide who can see/change what. This is more flexible in the long run. And more graceful to the user -- instead of getting a cryptic MySQL error message about permissions, the UI would simply not show what should not be shown. For updating, the UI would not even give the user the option.

相关文章