Start cqlsh
The CQL shell (cqlsh
) is a Python-based command line interface for running CQL commands interactively with support for tab completion.
cqlsh
requires Python 2.7 or Python 3.6 through 3.11.
Start the standalone cqlsh for Cassandra
-
See cqlsh: the CQL shell for details about
cqlsh
. -
Change to the directory where the tarball was extracted.
-
Start the
cqlsh
script, specifying the location (such as/usr/bin
) and other options as necessary.-
Start with default options and no authentication:
cqlsh
-
Connect to a specific node or use authentication:
cqlsh host_name port -u username -p password
Replace the following:
-
username
andpassword
: If authentication is enabled, provide a valid user and password for your cluster. For SSL-enabled clusters, see Providing Kerberos Credentials when Starting CQL Shell. -
host_name
andport
: To connect to a non-default node or a remote database, provide the IP address or hostname of a node in the cluster, such as10.100.176.166
, and the CQL port number, such as9042
.cqlsh
connects to127.0.0.1 9042
by default. To connect to a different node or remote database, you can either set the$CQLSH_HOST
and$CQLSH_PORT
environment variables or specify the host and port on the command line, such ascqlsh host_name port
. When a host and port number are given on the command line, they take precedence over any defaults.
-
-
Print the help menu for
cqlsh
:cqlsh --help
Use cqlshrc
for authentication
You can use a cqlshrc
file to set default credentials when launching cqlsh
.
For more information about the cqlshrc
file, see Configuring a cqlshrc file.
-
Create a file named
cqlshrc
or modify an existing one. -
Specify a role name and password or other authentication parameters, depending on your cluster configuration.
[authentication] username = name password = password123
-
Save the file in
home/.cassandra
directory or yourcqlsh
installation directory. -
Set permissions on the file to prevent unauthorized access if the password is stored in plain text. If you are using
cqlsh
in a production environment, use secure references for passwords. The file must be readable by the user that startscassandra
.chmod 440 'home/.cassandra/cqlshrc'
-
Check the permissions on
home/.cassandra/cqlshrc_history
to ensure that plain text passwords are not compromised.