mysqldatabasemysql-8.0

MySQL 8: Granting column level permissions?


I hope you can help me with my problem / question. I can´t give column level permissions to a SQL view. I have found several ways to do it on the internet but none of them work properly.

The sentence is as follows:

GRANT SELECT ON [db].[table] (column) TO [user]

I am wondering, if I have a SQL view with three columns, can I make a user only be able to see two columns of that same view?

Thanks to anyone who can help me.


Solution

  • The right syntax is:

    GRANT SELECT (col1, col2) ON mydb.mytbl TO 'someuser'@'somehost';
    

    Or if you want to include other accesses try:

    GRANT SELECT (col1), INSERT (col1, col2) ON mydb.mytbl TO 'someuser'@'somehost';
    

    Check doc for more info: https://dev.mysql.com/doc/refman/8.0/en/grant.html#grant-column-privileges