Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Cassandra Cqlsh

May 17, 2021 Cassandra

Table of contents

This chapter describes the Cassandra query language shell and explains how to use its commands.

By default, Cassandra provides a prompt for Cassandra query language shell (cqlsh), allowing users to communicate with it. With this shell, you can execute the Cassandra Query Language (CQL).

With cqlsh, you can

  • Define patterns,
  • Insert data,
  • Execute the query.

Start cqlsh

Start cqlsh with the command cqlsh, as shown below. It provides Cassandra cqlsh prompts as output.

[hadoop@linux bin]$ cqlsh
Connected to Test Cluster at
[cqlsh 5.0.1 | Cassandra 2.1.2 | CQL spec 3.2.0 | Native protocol v3]
Use HELP for help.

Cqlsh - As mentioned above, this command is used to start the cqlsh prompt. I n addition, it supports more options. The following table illustrates all the options for cqlsh and their usage.

Options Usage
cqlsh --help Show help topics for options for cqlsh commands.
cqlsh --version Provides the version of cqlsh that you are using.
cqlsh --color Indicates that the shell uses a colored output.
cqlsh --debug Show more debugging information.

cqlsh --execute


Instructs shell to accept and execute the CQL command.
cqlsh --file= “file name” If you use this option, Cassandra executes the command in a given file and exits.
cqlsh --no-color Indicates that Cassandra does not use color output.
cqlsh -u “user name” With this option, you can verify the user. The default user name is cassandra.
cqlsh-p “pass word” With this option, you can use a password to authenticate the user. The default password is cassandra.

Cqlsh command

Cqlsh has several commands that allow users to interact with it. The command is shown below.

Record the Shell command for

The shell command for the Cqlsh record is given below. These are commands for performing tasks such as displaying help topics, exiting cqlsh, descriptions, and so on.

  • HELP - Show help topics for all cqlsh commands.

  • CAPTURE - Captures the output of the command and adds it to the file.

  • CONSISTENCY - Displays the current consistency level, or sets a new consistency level.

  • COPY - Copy data to cassandra and copy data from Cassandra.

  • DESCRIBE - Describes the current cluster of Cassandra and its objects.

  • EXPAND - Scales up the output of the query.

  • EXIT - With this command, you can terminate cqlsh.

  • PAGING - Enable or disable query paging.

  • SHOW - Displays details of the current cqlsh session, such as Cassandra version, host or data type assumptions.

  • SOURCE - Executes a file that contains CQL statements.

  • TRACING - Enable or disable request tracking.

CQL data definition commands

  • CREATE KEYSPACE - Create KeySpace in Cassandra.

  • USE - Connect to keySpace that you've created.

  • ALTER KEYSPACE - Change the properties of KeySpace.

  • DROP KEYSPACE - Remove KeySpace.

  • CREATE TABLE - Create a table in KeySpace.

  • ALTER TABLE - Modify the column properties of the table.

  • DROP TABLE - Delete the table.

  • TRUNCATE - Remove all data from the table.

  • CREATE INDEX - Define a new index on a single column of a table.

  • DROP INDEX - Remove the named index.

CQL data operation instructions

  • INSERT - Add a column of rows to the table.

  • UPDATE - Update the column of the row.

  • DELETE - Remove data from the table.

  • BATCH - Execute multiple DML statements at once.

CQL words

  • SELECT - This clause reads data from the table

  • The WHERE-where clause is used with select to read specific data.

  • The ORDERBY - orderby clause is used with select to read specific data in a specific order.