MySQL的GRANT + WHERE [英] mysql GRANT + WHERE

查看:229
本文介绍了MySQL的GRANT + WHERE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想授予mysql中特定行的权限. 表:消息 cols:从,到,消息

I want to give permissions only to specificated rows in mysql. table: messages cols: from, to, message

GRANT ALL ON db.messages TO 'jeffrey'@'localhost' WHERE messages.from = 'jeffrey' OR messages.to = 'jeffrey' ;

通过这种方式,用户只能访问自己的消息.

With a thing like this the user only can access only his own messages.

您知道如何解决该问题吗?

Do you know how to solve the problem?

推荐答案

Per the GRANT command, there is no ability to set permission-levels on a per-row basis (table/columns, yes - but not the individual rows).

您可以设置查看来处理此问题但是,并授予用户访问该视图的权限.

You could setup a View to handle this though and grant the user permission to access the view instead.

如下所示的视图应为您提供基于当前用户的消息:

A view such as the following should give you the messages based on the current user:

CREATE VIEW user_messages AS
    SELECT *
    FROM messages
    WHERE
        messages.from = user() OR messages.to = user();

与拨款声明应该相似:

GRANT ALL ON db.user_messages TO 'jeffrey'@'localhost';

这篇关于MySQL的GRANT + WHERE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆