简体   繁体   English

Mysql:允许查询其他不可用的列?

[英]Mysql: allow query on an otherwise inaccesible column?

I have a table with a column that I want to prevent certain users from seeing. 我有一个表格,我希望阻止某些用户查看。 I understand that I should be able to do this using a view, ie have a view which excludes the particular column, and deny access to the table but allow access to the view (note, users do not need to be able to update the table/view). 我理解我应该能够使用视图执行此操作,即具有排除特定列的视图,并拒绝访问该表但允许访问视图(注意,用户无需更新表/视图)。

I do however want to allow an equality query against the field. 然而, 想允许针对该领域的平等查询。 Such as: 如:

SELECT * FROM some_table_or_view WHERE hidden_field = 'some_value';

To clarify: 澄清:

  • it should not be possible to have the hidden_field values be returned in a general query 不应该在一般查询中返回hidden_field
  • it should be possible to run a query with a constraint (preferably only an equality constraint) on the hidden_field value 应该可以在hidden_field值上运行具有约束(最好只是相等约束)的hidden_field

Is this possible? 这可能吗?

(EDIT: if there's a solution in a dbms other than Mysql, I'd be happy to hear about that, too). (编辑:如果在除mysql之外的dbms中有解决方案,我也很高兴听到这个)。

You can create a stored procedure which would return all the fields you allowed it to return, and then you can pass the hidden_value (filtering criterion) as a parameter. 您可以创建一个存储过程,该过程将返回您允许其返回的所有字段,然后您可以将hidden_​​value(过滤条件)作为参数传递。

Forbid your database users accessing the table, but allow them to call stored procedures. 禁止访问该表的数据库用户,但允许他们调用存储过程。

Then of course, you would have to create several stored procedures if you had several types of queries against the table. 当然,如果您对表有多种类型的查询,则必须创建多个存储过程。 But at least it solves your problem with the rights. 但至少它解决了你的权利问题。

No it is not. 不它不是。 Giving a user a possibility to filter the results with the column hidden_value means that they have select rights, and that also means they can see the column, and therefore select it. 为用户提供使用hidden_​​value列过滤结果的可能性意味着他们具有选择权限,这也意味着他们可以查看列,从而选择它。 Here http://dev.mysql.com/doc/refman/5.1/en/grant.html is a list of the rights you can grant or not grant to the users in mySQL. 这里http://dev.mysql.com/doc/refman/5.1/en/grant.html是您可以授予或不授予mySQL中用户权限的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM