CREATE USER
On this page
The CREATE USER command creates a new user account.
Syntax
CREATE USER [IF NOT EXISTS] user[@host][IDENTIFIED BY 'password'][WITH {DEFAULT RESOURCE POOL = poolname} |{FAILED_LOGIN_ATTEMPTS = integer PASSWORD_LOCK_TIME = integer} |{DEFAULT RESOURCE POOL = poolname FAILED_LOGIN_ATTEMPTS = integer PASSWORD_LOCK_TIME = integer}][REQUIRE {SSL | NONE}][ATTRIBUTE <valid json>][COMMENT <comment string>]
Note
Instead of authentication by password, the Kerberos, PAM, and SAML authentication types can also be used with the IDENTIFIED WITH clause:
IDENTIFIED WITH {authentication_
For example:
CREATE USER user IDENTIFIED WITH authentication_gss AS 'kerberos-spn';CREATE USER user IDENTIFIED WITH authentication_pam AS 'auth-string';
Arguments
-
user: Username of the SingleStore database user.
-
Non-JWT users: Maximum length of 32 characters.
-
JWT users: Maximum length of 320 characters.
-
-
host: The host that the user can connect from.
For example, specifying localhostmeans the user account can be used only when connecting from the local host.If no host is explicitly specified, the %wildcard is used, which allows the user to connect from any host. -
password: An optional database connection password for the user.
-
poolname: The default resource pool for the user.
FAILED_ LOGIN_ ATTEMPTS and PASSWORD_ LOCK_ TIME
FAILED_PASSWORD_, specifies the failed login attempt lockout behavior.FAILED_ is the number of failed attempts allowed after which the account is locked out.3 means that the account will be locked after three failed attempts.0, which means there is no restriction.1, PASSWORD_ must also be specified.
PASSWORD_FAILED_, specifies the failed login attempt lockout behavior.PASSWORD_ is the number of seconds a locked out account must wait before reattempting to log in.
Note
You must set both FAILED_ and PASSWORD_ to enable the lockout feature.
To modify the FAILED_ and PASSWORD_ for a user, or to unlock a locked user, use ALTER USER.
If an account is locked either manually using the ALTER USER … ACCOUNT LOCK command or automatically as a result of exceeding the values specified for FAILED_ and PASSWORD_ arguments, then restarting the cluster removes the lock and returns the account’s status to ONLINE.ACCOUNT_ column in the information_ view.
For more information about failed login attempt lockout behavior, refer to Securing SingleStore.
REQUIRE
REQUIRE supports the following options:
-
REQUIRE SSL: Ensures that the user connects via SSL. -
REQUIRE NONE: Specifies that SSL is not required for the connection.
ATTRIBUTE and COMMENT
Optional arguments used to provide additional information about a user.ATTRIBUTE must come first.ATTRIBUTE, the value must be a valid JSON object.
Remarks
-
The
CREATE USERcommand must be run by a user with administrative privileges on the database.Also, the new user does not have any privileges granted by default. Use GRANT to specify privileges for the new user. -
Other
CREATE USERcommand options aren’t applied in case the user exists andIF NOT EXISTSis specified; you must use theGRANTcommand to assign privileges or theALTER USERcommand to change user properties. -
The
WITHkeyword must be used with the following options and specified only once:-
DEFAULT RESOURCE POOL = <poolname> -
FAILED_LOGIN_ ATTEMPTS = integer PASSWORD_ LOCK_ TIME = <integer>
For example:
-
WITH DEFAULT RESOURCE POOL = pool1 FAILED_LOGIN_ ATTEMPTS = 10 PASSWORD_ LOCK_ TIME = 20 -
WITH FAILED_LOGIN_ ATTEMPTS = 10 PASSWORD_ LOCK_ TIME = 20 -
WITH DEFAULT RESOURCE POOL = pool1
-
-
This command causes implicit commits.
Refer to COMMIT for more information. -
The
CREATE USERcommand only applies to the current node unless thesync_engine variable is set topermissions ON. -
The
CREATE USERcommand holds a global lock on the cluster until the processing of the command is completed.Refer to Cluster Level Locks for more information. -
Users configured with
REQUIRE X509can log in is as follows:singlestore -u <user> \--ssl-ca=/path/to/ca.pem \--tls-version=TLSv1.2 \--ssl-cert=/path/to/client-cert.pem \--ssl-key=/path/to/client-key.pemThe
--ssl-cert,--ssl-keyand--ssl-caoptions must be specified for a user configured withREQUIRE X509, otherwise the login attempt results in an error.The client’s certificate is verified by the server during SSL authentication -
Refer to the Permissions Matrix for the required permissions.
-
Refer to Configuring a Password Policy for information on how to configure a robust password policy.
Examples
-
The following example demonstrates how to add a new user and grant the
SELECTprivilege on all tables in themydbdatabase to the user:CREATE USER joe;GRANT SELECT ON mydb.* TO 'joe'@'%'; -
The following example demonstrates how to create a resource pool and assign it to a new user in addition to controlling the login attempts:
CREATE RESOURCE POOL test_pool WITH QUERY_TIMEOUT = 20;CREATE USER user1 IDENTIFIED BY 'User123' WITH DEFAULT RESOURCE POOL = test_pool FAILED_LOGIN_ATTEMPTS = 3 PASSWORD_LOCK_TIME = 14400; -
The following example demonstrates the use of the
default_variable and therequire_ ssl REQUIREoption:CREATE USER `alice`@`%`; -- uses default_require_ssl var (off by default)CREATE USER `alice`@`%` REQUIRE NONE; -- does not require SSLCREATE USER `alice`@`%` REQUIRE SSL; -- requires SSL -
The following examples demonstrate the use of
ATTRIBUTEandCOMMENT:CREATE USER 'user1'@'svchost-xxxx' ATTRIBUTE '{"phone": "1234567890"}';CREATE USER 'user1'@'svchost-xxxx' COMMENT 'Some information about user1'; -
The following example demonstrates how to retrieve the
ATTRIBUTEandCOMMENTvalues from theinformation_view:schema. USERS CREATE USER singlestore@svchost-xxxx ATTRIBUTE '{"a": 1, "b": 2}' COMMENT 'Some information about the SingleStore user.';SELECT USER, ATTRIBUTE, COMMENT from INFORMATION_SCHEMA.USERS WHERE user='singlestore';+-------------+---------------+----------------------------------------------+ | USER | ATTRIBUTE | COMMENT | +-------------+---------------+----------------------------------------------+ | singlestore | {"a":1,"b":2} | Some information about the SingleStore user. | +-------------+---------------+----------------------------------------------+SELECT USER, ATTRIBUTE, COMMENT, ATTRIBUTE::a + ATTRIBUTE::b AS c FROM INFORMATION_SCHEMA.USERS WHERE user='singlestore';+-------------+---------------+----------------------------------------------+------+ | USER | ATTRIBUTE | COMMENT | c | +-------------+---------------+----------------------------------------------+------+ | singlestore | {"a":1,"b":2} | Some information about the SingleStore user. | 3 | +-------------+---------------+----------------------------------------------+------+ -
The following examples demonstrate assigning
REQUIRE X509to a user:CREATE USER 'user'@'localhost' REQUIRE X509;-- (or)CREATE USER 'user'@'localhost';ALTER USER 'user'@localhost' REQUIRE X509;-- (or)CREATE USER 'user'@'localhost';GRANT USAGE on *.* to 'user'@'localhost' REQUIRE X509;-- (or)CREATE USER 'user'@'localhost';CREATE ROLE 'role';GRANT USAGE on *.* to ROLE 'role' REQUIRE X509;CREATE GROUP 'group';GRANT ROLE 'role' to 'group';GRANT GROUP 'group' to 'user'@'localhost';
Last modified: