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 built-in cqlsh for DataStax Enterprise
-
Navigate to the DataStax Enterprise installation directory and locate the
bindirectory that containscqlsh. -
Start
cqlsh. For example, on macOS:cqlshIf authentication is enabled, provide a user name and password. For SSL-enabled clusters, see Providing Kerberos Credentials when Starting CQL Shell.
To start
cqlshon a non-default node, specify the IP address and port:cqlsh 100.0.0.75 9042 -
Print the help menu for
cqlsh:cqlsh --helpYou can use tab completion to see hints about how to complete a
cqlshcommand. Tab completion isn’t automatically installed for some platforms such as macOS. Use easy_install to install tab completion capabilities on macOS:easy_install readline
Start the standalone cqlsh for DataStax Enterprise
-
Install the standalone CQLSH tool that is compatible with your DataStax Enterprise version.
-
Change to the directory where the tarball was extracted.
-
Start the
cqlshscript, 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 passwordReplace the following:
-
usernameandpassword: 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_nameandport: 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.cqlshconnects to127.0.0.1 9042by default. To connect to a different node or remote database, you can either set the$CQLSH_HOSTand$CQLSH_PORTenvironment 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
cqlshrcor 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/.cassandradirectory or yourcqlshinstallation directory. -
Set permissions on the file to prevent unauthorized access if the password is stored in plain text. If you are using
cqlshin 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_historyto ensure that plain text passwords are not compromised.