* DOCSUP-2806: Add meta intro. * DOCSUP-2806: Update meta intro. * DOCSUP-2806: Fix meta. * DOCSUP-2806: Add quotes for meta headers. * DOCSUP-2806: Remove quotes from meta headers. * DOCSUP-2806: Add meta headers. * DOCSUP-2806: Fix quotes in meta headers. * DOCSUP-2806: Update meta headers. * DOCSUP-2806: Fix link to nowhere in EN. * DOCSUP-2806: Fix link (settings to tune) * DOCSUP-2806: Fix links. * DOCSUP-2806:Fix links EN * DOCSUP-2806: Fix build errors. * DOCSUP-2806: Fix meta intro. * DOCSUP-2806: Fix toc_priority in examples datasets TOC. * DOCSUP-2806: Fix items order in toc. * DOCSUP-2806: Fix order in toc. * DOCSUP-2806: Fix toc order. * DOCSUP-2806: Fix order in toc. * DOCSUP-2806: Fix toc index in create * DOCSUP-2806: Fix toc order in create. Co-authored-by: romanzhukov <romanzhukov@yandex-team.ru> Co-authored-by: alexey-milovidov <milovidov@yandex-team.ru>
3.8 KiB
toc_priority | toc_title |
---|---|
39 | USER |
CREATE USER
Creates a user account.
Syntax:
CREATE USER [IF NOT EXISTS | OR REPLACE] name [ON CLUSTER cluster_name]
[IDENTIFIED [WITH {NO_PASSWORD|PLAINTEXT_PASSWORD|SHA256_PASSWORD|SHA256_HASH|DOUBLE_SHA1_PASSWORD|DOUBLE_SHA1_HASH}] BY {'password'|'hash'}]
[HOST {LOCAL | NAME 'name' | REGEXP 'name_regexp' | IP 'address' | LIKE 'pattern'} [,...] | ANY | NONE]
[DEFAULT ROLE role [,...]]
[SETTINGS variable [= value] [MIN [=] min_value] [MAX [=] max_value] [READONLY|WRITABLE] | PROFILE 'profile_name'] [,...]
ON CLUSTER
clause allows creating users on a cluster, see Distributed DDL.
Identification
There are multiple ways of user identification:
IDENTIFIED WITH no_password
IDENTIFIED WITH plaintext_password BY 'qwerty'
IDENTIFIED WITH sha256_password BY 'qwerty'
orIDENTIFIED BY 'password'
IDENTIFIED WITH sha256_hash BY 'hash'
IDENTIFIED WITH double_sha1_password BY 'qwerty'
IDENTIFIED WITH double_sha1_hash BY 'hash'
User Host
User host is a host from which a connection to ClickHouse server could be established. The host can be specified in the HOST
query section in the following ways:
HOST IP 'ip_address_or_subnetwork'
— User can connect to ClickHouse server only from the specified IP address or a subnetwork. Examples:HOST IP '192.168.0.0/16'
,HOST IP '2001:DB8::/32'
. For use in production, only specifyHOST IP
elements (IP addresses and their masks), since usinghost
andhost_regexp
might cause extra latency.HOST ANY
— User can connect from any location. This is a default option.HOST LOCAL
— User can connect only locally.HOST NAME 'fqdn'
— User host can be specified as FQDN. For example,HOST NAME 'mysite.com'
.HOST NAME REGEXP 'regexp'
— You can use pcre regular expressions when specifying user hosts. For example,HOST NAME REGEXP '.*\.mysite\.com'
.HOST LIKE 'template'
— Allows you to use the LIKE operator to filter the user hosts. For example,HOST LIKE '%'
is equivalent toHOST ANY
,HOST LIKE '%.mysite.com'
filters all the hosts in themysite.com
domain.
Another way of specifying host is to use @
syntax following the username. Examples:
CREATE USER mira@'127.0.0.1'
— Equivalent to theHOST IP
syntax.CREATE USER mira@'localhost'
— Equivalent to theHOST LOCAL
syntax.CREATE USER mira@'192.168.%.%'
— Equivalent to theHOST LIKE
syntax.
!!! info "Warning"
ClickHouse treats user_name@'address'
as a username as a whole. Thus, technically you can create multiple users with the same user_name
and different constructions after @
. However, we don’t recommend to do so.
Examples
Create the user account mira
protected by the password qwerty
:
CREATE USER mira HOST IP '127.0.0.1' IDENTIFIED WITH sha256_password BY 'qwerty'
mira
should start client app at the host where the ClickHouse server runs.
Create the user account john
, assign roles to it and make this roles default:
CREATE USER john DEFAULT ROLE role1, role2
Create the user account john
and make all his future roles default:
ALTER USER user DEFAULT ROLE ALL
When some role is assigned to john
in the future, it will become default automatically.
Create the user account john
and make all his future roles default excepting role1
and role2
:
ALTER USER john DEFAULT ROLE ALL EXCEPT role1, role2