HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlModerate

Allow SELECT on specific column only

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
columnallowspecificselectonly

Problem

I have a User table with 3 column; name, email, password, etc.

I would like to create another user that can only SELECT the name column.

SELECT name     FROM User;    -- Ok!
SELECT email    FROM User;    -- Not Ok!


Can this be done on MySQL?

Solution

For this you need to grant select permission to user (MySQL User) on that particular column of table.

GRANT SELECT (name) ON MyDb.User TO 'MySQLUser'@'MySQLHost';


For explanation have a look at MySQL Documentation on column Privileges

Code Snippets

GRANT SELECT (name) ON MyDb.User TO 'MySQLUser'@'MySQLHost';

Context

StackExchange Database Administrators Q#45708, answer score: 19

Revisions (0)

No revisions yet.