2

I'm trying to create user in cassandra using python driver. defined variable password

password=abcde
rows = session.execute("create user test_user with 'password') 

Syntax error in CQL query] message="line password expecting K_PASSWORD

password=abcde
rows = session.execute("create user test_user with 'password') 

1 Answer 1

2

You're missing the PASSWORD reserved word in your syntax. Also, CREATE USER is only used with versions of Cassandra prior to 3.x. It's CREATE ROLE if you're on a version after that.

Versions below 3.x

CREATE USER test_user WITH PASSWORD 'abcde';

3.x+

CREATE ROLE test_user WITH PASSWORD='abcde';

Note that the newer versions require the password and PASSWORD to be separated by an equals ('=') symbol.

So in your Python script, it'd look something like this:

rows = session.execute("create role test_user with password='" + password1 + "' and login=true")
Sign up to request clarification or add additional context in comments.

6 Comments

Which version of Cassandra are you running? @cad
Cassandra 3.11.1
@cad Ok, then as per my examples, make sure to use an equal sign and the word “role” instead of “user.” Also try putting the password text in quotes.
role with the syntax you mentioned above works but wouldn't be able to login as login=true is not mentioned. and tried login=true it errors out with invalid synatx. CREATE ROLE test_user with password='" + password1 + "'" AND LOGIN = true
@cad edit made. Sorry, I assumed that the password was the hard part and that you could figure out the rest. You have to treat ` and login=true` as a substring and concatenate on to the original string.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.