To revoke privileges, use the [REVOKE](../../sql-reference/statements/revoke.md) statement. Also you can list granted privileges with the [SHOW GRANTS](../../sql-reference/statements/show.md#show-grants-statement) statement.
GRANT [ON CLUSTER cluster_name] privilege[(column_name [,...])] [,...] ON {db.table|db.*|*.*|table|*} TO {user | role | CURRENT_USER} [,...] [WITH GRANT OPTION]
The `WITH GRANT OPTION` clause grants `user` or `role` with permission to execute the `GRANT` query. Users can grant privileges of the same scope they have and less.
It means that `john` has the permission to execute:
-`SELECT x,y FROM db.table`.
-`SELECT x FROM db.table`.
-`SELECT y FROM db.table`.
`john` can’t execute `SELECT z FROM db.table`. The `SELECT * FROM db.table` also is not available. Processing this query, ClickHouse doesn’t return any data, even `x` and `y`. The only exception is if a table contains only `x` and `y` columns. In this case ClickHouse returns all the data.
Also `john` has the `GRANT OPTION` privilege, so it can grant other users with privileges of the same or smaller scope.
Specifying privileges you can use asterisk (`*`) instead of a table or a database name. For example, the `GRANT SELECT ON db.* TO john` query allows `john` to execute the `SELECT` query over all the tables in `db` database. Also, you can omit database name. In this case privileges are granted for current database. For example, `GRANT SELECT ON * TO john` grants the privilege on all the tables in the current database, `GRANT SELECT ON mytable TO john` grants the privilege on the `mytable` table in the current database.
Access to the `system` database is always allowed (since this database is used for processing queries).
You can grant multiple privileges to multiple accounts in one query. The query `GRANT SELECT, INSERT ON *.* TO john, robin` allows accounts `john` and `robin` to execute the `INSERT` and `SELECT` queries over all the tables in all the databases on the server.
## Privileges {#grant-privileges}
Privilege is a permission to execute specific kind of queries.
Privileges have a hierarchical structure. A set of permitted queries depends on the privilege scope.
Hierarchy of privileges:
- [SELECT](#grant-select)
- [INSERT](#grant-insert)
- [ALTER](#grant-alter)
-`ALTER TABLE`
-`ALTER UPDATE`
-`ALTER DELETE`
-`ALTER COLUMN`
-`ALTER ADD COLUMN`
-`ALTER DROP COLUMN`
-`ALTER MODIFY COLUMN`
-`ALTER COMMENT COLUMN`
-`ALTER CLEAR COLUMN`
-`ALTER RENAME COLUMN`
-`ALTER INDEX`
-`ALTER ORDER BY`
-`ALTER ADD INDEX`
-`ALTER DROP INDEX`
-`ALTER MATERIALIZE INDEX`
-`ALTER CLEAR INDEX`
-`ALTER CONSTRAINT`
-`ALTER ADD CONSTRAINT`
-`ALTER DROP CONSTRAINT`
-`ALTER TTL`
-`ALTER MATERIALIZE TTL`
-`ALTER SETTINGS`
-`ALTER MOVE PARTITION`
-`ALTER FETCH PARTITION`
-`ALTER FREEZE PARTITION`
-`ALTER VIEW`
-`ALTER VIEW REFRESH`
-`ALTER VIEW MODIFY QUERY`
- [CREATE](#grant-create)
-`CREATE DATABASE`
-`CREATE TABLE`
-`CREATE VIEW`
-`CREATE DICTIONARY`
-`CREATE TEMPORARY TABLE`
- [DROP](#grant-drop)
-`DROP DATABASE`
-`DROP TABLE`
-`DROP VIEW`
-`DROP DICTIONARY`
- [TRUNCATE](#grant-truncate)
- [OPTIMIZE](#grant-optimize)
- [SHOW](#grant-show)
-`SHOW DATABASES`
-`SHOW TABLES`
-`SHOW COLUMNS`
-`SHOW DICTIONARIES`
- [KILL QUERY](#grant-kill-query)
- [ACCESS MANAGEMENT](#grant-access-management)
-`CREATE USER`
-`ALTER USER`
-`DROP USER`
-`CREATE ROLE`
-`ALTER ROLE`
-`DROP ROLE`
-`CREATE ROW POLICY`
-`ALTER ROW POLICY`
-`DROP ROW POLICY`
-`CREATE QUOTA`
-`ALTER QUOTA`
-`DROP QUOTA`
-`CREATE SETTINGS PROFILE`
-`ALTER SETTINGS PROFILE`
-`DROP SETTINGS PROFILE`
-`SHOW ACCESS`
-`SHOW_USERS`
-`SHOW_ROLES`
-`SHOW_ROW_POLICIES`
-`SHOW_QUOTAS`
-`SHOW_SETTINGS_PROFILES`
-`ROLE ADMIN`
- [SYSTEM](#grant-system)
-`SYSTEM SHUTDOWN`
-`SYSTEM DROP CACHE`
-`SYSTEM DROP DNS CACHE`
-`SYSTEM DROP MARK CACHE`
-`SYSTEM DROP UNCOMPRESSED CACHE`
-`SYSTEM RELOAD`
-`SYSTEM RELOAD CONFIG`
-`SYSTEM RELOAD DICTIONARY`
-`SYSTEM RELOAD EMBEDDED DICTIONARIES`
-`SYSTEM MERGES`
-`SYSTEM TTL MERGES`
-`SYSTEM FETCHES`
-`SYSTEM MOVES`
-`SYSTEM SENDS`
-`SYSTEM DISTRIBUTED SENDS`
-`SYSTEM REPLICATED SENDS`
-`SYSTEM REPLICATION QUEUES`
-`SYSTEM SYNC REPLICA`
-`SYSTEM RESTART REPLICA`
-`SYSTEM FLUSH`
-`SYSTEM FLUSH DISTRIBUTED`
-`SYSTEM FLUSH LOGS`
- [INTROSPECTION](#grant-introspection)
-`addressToLine`
-`addressToSymbol`
-`demangle`
- [SOURCES](#grant-sources)
-`FILE`
-`URL`
-`REMOTE`
-`YSQL`
-`ODBC`
-`JDBC`
-`HDFS`
-`S3`
- [dictGet](#grant-dictget)
Examples of how this hierarchy is treated:
- The `ALTER` privilege includes all other `ALTER*` privileges.
-`ALTER CONSTRAINT` includes `ALTER ADD CONSTRAINT` and `ALTER DROP CONSTRAINT` privileges.
Privileges are applied at different levels. Knowing of a level suggests syntax available for privilege.
Levels (from lower to higher):
-`COLUMN` — Privilege can be granted for column, table, database, or globally.
-`TABLE` — Privilege can be granted for table, database, or globally.
-`VIEW` — Privilege can be granted for view, database, or globally.
-`DICTIONARY` — Privilege can be granted for dictionary, database, or globally.
-`DATABASE` — Privilege can be granted for database or globally.
-`GLOBAL` — Privilege can be granted only globally.
-`GROUP` — Groups privileges of different levels. When `GROUP`-level privilege is granted, only that privileges from the group are granted which correspond to the used syntax.
Examples of allowed syntax:
-`GRANT SELECT(x) ON db.table TO user`
-`GRANT SELECT ON db.* TO user`
Examples of disallowed syntax:
-`GRANT CREATE USER(x) ON db.table TO user`
-`GRANT CREATE USER ON db.* TO user`
The special privilege [ALL](#grant-all) grants all the privileges to a user account or a role.
By default, a user account or a role has no privileges.
If a user or a role has no privileges, it is displayed as [NONE](#grant-none) privilege.
Some queries by their implementation require a set of privileges. For example, to execute the [RENAME](../../sql-reference/statements/misc.md#misc_operations-rename) query you need the following privileges: `SELECT`, `CREATE TABLE`, `INSERT` and `DROP TABLE`.
User granted with this privilege can execute `SELECT` queries over a specified list of columns in the specified table and database. If user includes other columns then specified a query returns no data.
This privilege allows `john` to execute any `SELECT` query that involves data from the `x` and/or `y` columns in `db.table`, for example, `SELECT x FROM db.table`. `john` can’t execute `SELECT z FROM db.table`. The `SELECT * FROM db.table` also is not available. Processing this query, ClickHouse doesn’t return any data, even `x` and `y`. The only exception is if a table contains only `x` and `y` columns, in this case ClickHouse returns all the data.
User granted with this privilege can execute `INSERT` queries over a specified list of columns in the specified table and database. If user includes other columns then specified a query doesn’t insert any data.
- To stop mutation by the [KILL MUTATION](../../sql-reference/statements/misc.md#kill-mutation-statement) query, you need to have a privilege to start this mutation. For example, if you want to stop the `ALTER UPDATE` query, you need the `ALTER UPDATE`, `ALTER TABLE`, or `ALTER` privilege.
Allows executing [CREATE](../../sql-reference/statements/create.md) and [ATTACH](../../sql-reference/statements/misc.md#attach) DDL-queries according to the following hierarchy of privileges:
Allows executing [DROP](../../sql-reference/statements/misc.md#drop) and [DETACH](../../sql-reference/statements/misc.md#detach-statement) queries according to the following hierarchy of privileges:
Allows using external data sources. Applies to [table engines](../../engines/table-engines/index.md) and [table functions](../../sql-reference/table-functions/index.md#table-functions).
The `SOURCES` privilege enables use of all the sources. Also you can grant a privilege for each source individually. To use sources, you need additional privileges.
- To create a table with the [MySQL table engine](../../engines/table-engines/integrations/mysql.md), you need `CREATE TABLE (ON db.table_name)` and `MYSQL` privileges.
- To use the [mysql table function](../../sql-reference/table-functions/mysql.md), you need `CREATE TEMPORARY TABLE` and `MYSQL` privileges.
Allows a user to execute [dictGet](../../sql-reference/functions/ext-dict-functions.md#dictget), [dictHas](../../sql-reference/functions/ext-dict-functions.md#dicthas), [dictGetHierarchy](../../sql-reference/functions/ext-dict-functions.md#dictgethierarchy), [dictIsIn](../../sql-reference/functions/ext-dict-functions.md#dictisin) functions.