...

/

The Cassandra Shell

The Cassandra Shell

Explore the Cassandra shell cqlsh, and practice executing basic cqlsh commands.

In this lesson, we will cover the Cassandra shell cqlsh, a command-line interface, provided by Apache Cassandra, which comes installed, located in the bin/ directory. cqlsh uses Python native protocol driver to connect with a Cassandra node and execute CQL commands.

To start the CQL shell, type cqlsh once the cluster is up and running. To connect to a specific host, specify the IP address and port after the cqlsh keyword. In the absence of a port, the default port 9042 is used for the connection. 

cqlsh [options] [host [port]]

Commands exit or quit are used to end the current cqlsh session. 

cqlsh is case insensitive. So exit, Exit or EXIT are all treated the same.

This course will follow the convention of using uppercase for CQL keywords, and lowercase for other identifiers.

CQL history file

By default, Cassandra maintains a history of all executed CQL commands in the ~/.cassandra/cql_history file. A different path for the file can be set using the environment variable CQL_HISTORY. To disable history recording, CQL_HISTORY can be set to /dev/null

CQL shell options

The CQL shell allows several options to be specified for the session after the cqlsh keyword.

cqlsh [options] [host [port]]

A few key options are listed in the table below:

Short Option

Long Option

Description

--version

Display cqlsh version 

-h

--help

Display syntax and available options for CQL shell

--color

Display colored output

--no-color

Do not display coloured output

-u userName

--username ="userName"

Connect using the given username 

-p pasword

--password="pasword"

Connect using the given password

-k keyspaceName   

--keyspace keyspaceName or --keyspace = "keyspaceName"

USE the keyspace provided, once connected

-f fileName   

--file=fileName

Execute commands listed in the .cql file and exit cqlsh

-e "statement"

--execute="statement"

Execute the CQL statement provided and exit cqlsh

...