0

I create an user called abc. Now I need to grant read privilege to him. But he should be get read privilege only for the views in database. How can I implement this?

halfer
  • 19,824
  • 17
  • 99
  • 186
Isuru Herath
  • 298
  • 6
  • 20

2 Answers2

3

Documentation

GRANT SELECT ON database.view TO 'abc'@'localhost';

Also, there is a neat trick, which (combined with SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW'; ) will allow you to generate code for all views you need.

Community
  • 1
  • 1
Alexander
  • 3,129
  • 2
  • 19
  • 33
  • Thank you very much. Here I have more than one view. I need to give priviledges to all the views. – Isuru Herath Feb 14 '14 at 18:08
  • 1
    @IsuruHerath You can easily do this with a script. Simply get list of all views `SHOW FULL TABLES IN database_name WHERE TABLE_TYPE LIKE 'VIEW';` and store in array, and then go through array giving the permissions on each item! For example, you can do this with bash or php – Alexander Feb 14 '14 at 18:27
  • But I have asked to write a querry for this. – Isuru Herath Feb 14 '14 at 18:33
  • @IsuruHerath tell the person, who asked you, that this is impossible – Alexander Feb 14 '14 at 18:35
  • @IsuruHerath have you finished your task? Was I right, when told you, that this can't be done? – Alexander Feb 22 '14 at 18:49
0

You can use GRANT http://dev.mysql.com/doc/refman/5.1/en/grant.html#grant-privileges

GRANT SELECT ON db2.invoice TO 'jeffrey'@'localhost';
Hett
  • 3,484
  • 2
  • 34
  • 51