如何向除一列之外的所有列授予权限?
我想授予用户更新
权限来更新除一列之外的所有列 - 在我的情况下 - Id(更改 Id 可能会导致数据、现有 URL 等混乱。 - 外键不会 一个解决方案)。 mysql 中是否可以不列出所有其他列?例如,以某种方式说:
grant update on db.table to user;
NOT grant update id on db.table to user;
或类似的话?
我不想列出所有列的原因:
它更强大 - 我经常稍后向表中添加一些列,我可能会忘记我还必须更新此规则,
我没有
grant
权限,因此我必须要求我的托管提供商运行每个grant
命令,所以我想尽量减少这些请求是一项高于标准的服务(这是他们对我的恩典)。
特别是对于 mysql,但我也对 gereric sql 解决方案感兴趣。
I want to grant user an update
privilege to update all columns except one - Id in my case (changing Id could make a mess in data, existing URLs etc. - foreign keys are not a solution). Is it possible in mysql without listing all the other columns? E.g. somehow by saying:
grant update on db.table to user;
NOT grant update id on db.table to user;
or something like that?
Reasons why I don't want to list all the columns:
it is more robust - I often add some columns to tables later and I would probably forget that I must also update this rule,
I don't have the
grant
permission so I must ask my hosting provider to run everygrant
command, so I want to minimize these requests as it is an above-standard service (it's their grace to me).
Particularly for mysql, but I'm also interested in gereric sql solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您应该了解有关数据库完整性的更多信息,例如外键。
外键是数据库关系系统保持完整性的方式。来自 mySql FK 文档:
避免使用外键损坏有一些优点:
由于OP注释而编辑
不可能授予对象高级权限,然后撤销低级权限。看看
href="https://stackoverflow.com/questions/8131849/selective-privileges-in-mysql">MySQL 中的选择性权限(并投票 ,选择所有字段的权限并仅更新非 id 字段,您可以编写一个脚本来执行此操作,
我希望这最终能回答您的问题。
You should learn more about database integrity, just about foreign keys.
Foreign Keys are the way that Dabase Relational system keep integrity with out artifices. From mySql FK documentation:
Avoid corruption with Foreign key has some advantages:
EDITED due OP comments
It is not possible to grant a high level privilete over an object and then revoke a low level one, take a look to selective privileges in MySQL (and vote up the answer).
That means that you should grant insert privileges over table, select privileges over all fields and update only over non id fields. You can write a script that do this for you.
I hope this finally answer your question.
AFAIK这是不可能的,如果你担心数据库一致性,你应该使用外键约束来保持数据库一致性。
AFAIK it is not possible, if you are afraid of database consistency, you should use foreign key constraint to keep the database consistency.
创建对数据执行(选择、插入、更新、删除)操作的存储过程。
仅允许用户访问过程,而不是表。
Create stored procedures that do (Select, Insert, Update, Delete) operations on the data.
Give to the user access to the procedures only, not to the tables.
这是不可能的 - 有关更多详细信息,请参阅此问题。
It is not possible - for more details see this question.
我想这可能有效:-
I guess this might works :-