DBAtlas · Database operations atlas

Create a user and grant privileges

Oracle

CREATE USER app IDENTIFIED BY "Strong#Pass1";
GRANT CREATE SESSION TO app;
GRANT SELECT, INSERT, UPDATE ON hr.employee TO app;

Without CREATE SESSION the user cannot connect. For a quota: ALTER USER app QUOTA 100M ON users;

PostgreSQL

CREATE ROLE app LOGIN PASSWORD 'Strong#Pass1';
GRANT CONNECT ON DATABASE mydb TO app;
GRANT USAGE ON SCHEMA public TO app;
GRANT SELECT, INSERT, UPDATE ON ALL TABLES IN SCHEMA public TO app;

For tables created in the future: ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO app;

MySQL

CREATE USER 'app'@'%' IDENTIFIED BY 'Strong#Pass1';
GRANT SELECT, INSERT, UPDATE ON mydb.* TO 'app'@'%';

'%' allows connections from any host; for security, specify a particular IP/host where possible. CREATE USER/GRANT take effect immediately; FLUSH PRIVILEGES is needed only if DML was run directly against the grant tables.

SQL Server

CREATE LOGIN app WITH PASSWORD = 'Strong#Pass1';
USE mydb;
CREATE USER app FOR LOGIN app;
GRANT SELECT, INSERT, UPDATE ON SCHEMA::dbo TO app;

A login is server-wide; a user is created separately in each database. For a role: ALTER ROLE db_datareader ADD MEMBER app;

MongoDB

db.createUser({
  user: "app",
  pwd: "Strong#Pass1",
  roles: [ { role: "readWrite", db: "mydb" } ]
})

The db in which the user is created becomes its auth db. Built-in roles: read, readWrite, dbAdmin, clusterAdmin...

Redis

ACL SETUSER app on >Strong#Pass1 ~app:* +@read +@write
# To persist: ACL SAVE if an aclfile is defined, otherwise CONFIG REWRITE (users are written to redis.conf)

on = enabled, >password adds a password, ~app:* is the key pattern, +@read/+@write are command categories. If not persisted, it is lost on restart: ACL SAVE works only when an aclfile is configured and returns an error otherwise; in that case use CONFIG REWRITE.

Open in DBAtlas →