CREATE USER

On this page Carat arrow pointing down

The CREATE USER statement creates SQL users, which let you control privileges on your databases and tables.

Tip:

You can also use the cockroach user set command to create and manage users.

Considerations

Required privileges

The user must have the INSERT and UPDATE privileges on the system.users table.

Synopsis

CREATE USER IF NOT EXISTS name WITH PASSWORD password

Parameters

Parameter Description
user_name The name of the user you want to create.

Usernames are case-insensitive; must start with either a letter or underscore; must contain only letters, numbers, or underscores; and must be between 1 and 63 characters.
password Let the user authenticate their access to a secure cluster using this password. Passwords must be entered as string values surrounded by single quotes (').

Password creation is supported only in secure clusters for non-root users. The root user must authenticate with a client certificate and key.

User authentication

Secure clusters require users to authenticate their access to databases and tables. CockroachDB offers two methods for this:

  • Client certificate and key authentication, which is available to all users. To ensure the highest level of security, we recommend only using client certificate and key authentication.

  • Password authentication, which is available to non-root users who you've created passwords for. To create a user with a password, use the WITH PASSWORD clause of CREATE USER. To add a password to an existing user, use the cockroach user command.

    Users can use passwords to authenticate without supplying client certificates and keys; however, we recommend using certificate-based authentication whenever possible.

    Password creation is supported only in secure clusters.

Examples

Create a user

Usernames are case-insensitive; must start with either a letter or underscore; must contain only letters, numbers, or underscores; and must be between 1 and 63 characters.

icon/buttons/copy
> CREATE USER jpointsman;

After creating users, you must:

Create a user with a password

icon/buttons/copy
> CREATE USER jpointsman WITH PASSWORD 'Q7gc8rEdS';

Password creation is supported only in secure clusters for non-root users. The root user must authenticate with a client certificate and key.

Manage users

After creating users, you can manage them using the cockroach user command.

Authenticate as a specific user

Secure clusters with client certificates

All users can authenticate their access to a secure cluster using a client certificate issued to their username.

icon/buttons/copy

$ cockroach sql --user=jpointsman

Secure clusters with passwords

Users with passwords can authenticate their access by entering their password at the command prompt instead of using their client certificate and key.

If we cannot find client certificate and key files matching the user, we fall back on password authentication.

icon/buttons/copy
$ cockroach sql --user=jpointsman

icon/buttons/copy

$ cockroach sql --insecure --user=jpointsman

See also


Yes No
On this page

Yes No