Suitable for versions above cassandra 2.0
1. First modify the configuration file cassandra.yaml
Set the default authenticator: AllowAllAuthenticator to run everyone login to log in with a password:
authenticator: PasswordAuthenticator
2. Log in to cassandra to create a user
Log in to cassandra with the default account
Execute in the bin directory
./cqlsh -ucassandra -pcassandra
create user
CREATE USER myusername WITH PASSWORD 'mypassword' SUPERUSER ;
3. Login with new user
Delete the default account:
DROP USER cassandra ;
4. Java uses username and password to access cassandra
Cluster cluster = Cluster.builder() .addContactPoint("192.168.22.161") .withCredentials("myusername", "mypassword") .build();