Skip to main content

How do you create a user?

A user is created with the CREATE USER command.

General syntax:

sql
CREATE USER username WITH PASSWORD 'password';

Example

sql
CREATE USER analyst WITH PASSWORD 'secure123';

Once created, you can grant them access rights:

sql
GRANT CONNECT ON DATABASE company TO analyst; GRANT SELECT, INSERT ON TABLE employees TO analyst;

The syntax varies slightly by DBMS:

  • In PostgreSQL, you use CREATE USER or CREATE ROLE;

  • In MySQL, it looks like this:

    sql
    CREATE USER 'analyst'@'localhost' IDENTIFIED BY 'secure123';

Summary: the CREATE USER command creates the account, and GRANT sets its permissions and access to database objects.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.

How do you create a user?: SQL Interview Question