Overview
The mysql.columns_priv view is used to view the column privileges granted to users.
Columns
Field |
Type |
Nullable |
Description |
|---|---|---|---|
| Host | varchar(255) | NO | The hostname to which the privilege is granted. If it is set to '%', the privilege is granted to all hosts. |
| Db | varchar(128) | NO | Name of the database to which the table belongs |
| User | varchar(128) | NO | Name of the user to whom the privilege is granted |
| Table_name | varchar(128) | NO | Table name |
| Column_name | varchar(128) | NO | Column Name |
| Column_priv | varchar(31) | NO | Column privileges, including SELECT, INSERT, and UPDATE. |
| Timestamp | datetime | YES | Timestamp, indicating the time when the permission was last modified. |
Sample query
Grant the user u1 the SELECT privilege on column c1 and the UPDATE privilege on column c2 of table t1.
obclient [mysql]> grant select(c1), update(c2) on t1 to u1;Check the column privileges granted to user u1.
obclient [mysql]> select * from mysql.columns_priv;The query result is as follows:
+------+------+------+------------+-------------+-------------+---------------------+ | Host | Db | User | Table_name | Column_name | Column_priv | Timestamp | +------+------+------+------------+-------------+-------------+---------------------+ | % | test | u1 | t1 | c2 | Update | 2024-04-24 14:38:20 | | % | test | u1 | t1 | c1 | Select | 2024-04-24 14:38:20 | +------+------+------+------------+-------------+-------------+---------------------+ 2 rows in set (0.092 sec)