CREATE USER (Deprecated)
CREATE USER
is supported for backwards compatibility only.
Authentication and authorization for DataStax Enterprise 5.0 and later are based on ROLES
, and use CREATE ROLE
instead.
CREATE USER
defines a new database user account.
By default users accounts do not have superusersuperuser status.
Only a superuser can issue CREATE USER
requests.
See CREATE ROLE for more information about SUPERUSER
and NOSUPERUSER
.
User accounts are required for logging in under internal authentication and authorization.
Enclose the user name in single quotation marks if it contains non-alphanumeric characters. You cannot recreate an existing user. To change the superuser status, password or hashed password, use ALTER USER.
Synopsis
CREATE USER [ IF NOT EXISTS ] <user_name> ( WITH PASSWORD '<user_password>' | WITH HASHED PASSWORD '<hashed_user_password>' ) [ ( SUPERUSER | NOSUPERUSER ) ] ;
Syntax legend
Syntax conventions | Description |
---|---|
UPPERCASE |
Literal keyword. |
Lowercase |
Not literal. |
|
Variable value. Replace with a user-defined value. |
|
Optional.
Square brackets ( |
|
Group.
Parentheses ( |
|
Or.
A vertical bar ( |
|
Repeatable.
An ellipsis ( |
|
Single quotation ( |
|
Map collection.
Braces ( |
Set, list, map, or tuple.
Angle brackets ( |
|
|
End CQL statement.
A semicolon ( |
|
Separate the command line options from the command arguments with two hyphens ( |
|
Search CQL only: Single quotation marks ( |
|
Search CQL only: Identify the entity and literal value to overwrite the XML element in the schema and solrConfig files. |
Examples
Creating internal user accounts
Use WITH PASSWORD
to create a user account for internal authentication, ennclosing the password in single quotation marks:
CREATE USER spillman WITH PASSWORD 'Niner27';
If internal authentication has not been set up, WITH PASSWORD
is not required:
CREATE USER tony NOSUPERUSER;
Use WITH HASHED PASSWORD
to create a user account for internal authentication with a hashed password enclosed in single quotation marks:
CREATE USER jane
WITH HASHED PASSWORD = '$2a$10$xsAJKfU.ZUzcuM9REniQoO8jUzBx0B.ChEl5w86TFcOv5ZhARo/uq';
Create a user as a superuser:
CREATE USER akers WITH PASSWORD 'Niner2' SUPERUSER;
or as a non-superuser:
CREATE USER akers WITH PASSWORD 'Niner75' NOSUPERUSER;
Note that a password and superuser status can be set in one command.
Creating a user account conditionally
You can test that the user does not have an account before attempting to create one.
Attempting to create an existing user results in an invalid query condition unless the IF NOT EXISTS
option is used.
If the option is used, the statement will be a no-op if the user exists.
Create a user with IF NOT EXISTS
:
CREATE USER bonnie IF NOT EXISTS WITH PASSWORD 'heydo';