How to create user in Cassandra Database :-
To create user one should use "CREATE ROLE" instead of "CREATE USER" . CREATE USER is now decrypted but still works due to support older version of cassandra. User accounts are required for logging in under internal authentication and authorization. Below is the syntax to add new user in database.
CREATE USER [IF NOT EXISTS] user_name
WITH PASSWORD 'password'
[SUPERUSER | NOSUPERUSER]
OR
CREATE ROLE [IF NOT EXISTS] role_name
[WITH SUPERUSER = true | false
| LOGIN = true | false
| PASSWORD = 'password'
| OPTIONS = option_map]
Examples :-
cassandra@cqlsh> create user demo1 with password 'demo1';
cassandra@cqlsh> create user admin with password 'admin' superuser;
cassandra@cqlsh> CREATE USER IF NOT EXISTS demo1 WITH PASSWORD 'password';
cassandra@cqlsh> create user admin with password 'admin' superuser;
cassandra@cqlsh> CREATE USER IF NOT EXISTS demo1 WITH PASSWORD 'password';
if you use "IF NOT EXISTS" in create user statement then your create user statement will not through error if user is already exists. It doesn't do anything but if user is not present then it creates user.
cassandra@cqlsh> CREATE ROLE JOE WITH SUPERUSER = true AND LOGIN = true AND PASSWORD = 'joe123';
cassandra@cqlsh> CREATE ROLE SAM WITH SUPERUSER = false AND LOGIN = true AND PASSWORD = 'sam123';
cassandra@cqlsh> CREATE ROLE SAM WITH SUPERUSER = false AND LOGIN = true AND PASSWORD = 'sam123';
If you are using "CREATE ROLE" then you should use "LOGIN=true" to allow users to login.
Note: Those who are familiar with Oracle Database please don't get confuse with role and user. In oracle role and user are different but in cassandra its almost same only difference is if use LOGIN=false then it will be treated as role. In Cassandra role and user are same thing.
Drop user :-
cassandra@cqlsh> drop role SAM;
cassandra@cqlsh> drop role JOE;
cassandra@cqlsh> drop user admin;
cassandra@cqlsh> drop user demo1;
No comments:
Post a Comment