DEFINE
statement
LOGIN
DEFINE LOGIN
statement
Use the DEFINE LOGIN
statement to create user accounts on SurrealDB.
Requirements
- You must be authenticated as a root or Namespace user to create a Namespace level account using the
DEFINE LOGIN
statement. - You must be authenticated as a root, Namespace, or Database user to create a Database level account using the
DEFINE LOGIN
statement. - You must select your namespace and/or database before you can use the
DEFINE LOGIN
statement.
Note: You cannot use the DEFINE LOGIN
statement to create a root or SCOPE
user.
Statement syntax
DEFINE LOGIN @name ON [ NAMESPACE | DATABASE ] [ PASSWORD @pass | PASSHASH @hash ]
Example usage
The following example shows how you can create a NAMESPACE
user using the DEFINE LOGIN
statement.
-- Specify the namespace
USE NS abcum;
-- Create the user
DEFINE LOGIN username ON NAMESPACE PASSWORD '123456';
The following example shows how you can create a DATABASE
user using the DEFINE LOGIN
statement.
-- Specify the namespace and database for the user
USE NS abcum DB app_vitalsense;
-- Create the user
DEFINE LOGIN username ON DATABASE PASSWORD '123456';