Cassandra – Cqlsh Commands

In this tutorial, we will learn about the cqlsh commands. In Cassandra, cqlsh commands can be used through CQL interactive terminal. These commands will work only within the Cqlsh shell.

SHOW VERSION – This command will show you the cqlsh, Cassandra, CQL, and native protocol versions.

Example:

casa@casa1:~$ cqlsh
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.10 | CQL spec 3.4.4 | Native protocol v4]
Use HELP for help.
cqlsh>

 

SHOW HOST – This command will give you the IP address and port number, cluster name.

Example:

cqlsh> show host
Connected to Test Cluster at 127.0.0.1:9042.
cqlsh>

 

SOURCE – This command allow you to read the contents of a file and executes CQL statements in the file.

Syntax:

SOURCE <string filename>

Example:

cqlsh> SOURCE '/home/cassandra/Execute.cql'

 

CAPTURE – This command will capture the command output and append to a mentioned file.

Syntax:

CAPTURE '<file>';
CAPTURE OFF;
CAPTURE;

 

HELP – This command will provide us the information about cqlsh commands.

TRACING – This Command Enables or disables tracing in cqlsh command prompt.

Syntax:

TRACING ON
TRACING OFF

 

PAGING – This command enables or disables paging, or set the page size. This will be helpful when we have large content as output.

Syntax:

PAGING ON
PAGING OFF
PAGING <page size in rows>

 

EXPAND – This command enables or disables vertical printing of rows. Enabling EXPAND is useful when many columns are fetched.

Syntax:

EXPAND ON
EXPAND OFF

 

LOGIN – This command Authenticate the Cassandra user for the current session.

Syntax:

LOGIN <username> [<password>]

 

EXIT – This command will end the current session and terminates the cqlsh process.

Syntax:

EXIT
QUIT

 

CLEAR – This command clears the console.

Syntax:

CLEAR
CLS

 

DESCRIBE – This command gives the description of all below Schema Elements.

Syntax:

DESCRIBE CLUSTER
DESCRIBE SCHEMA
DESCRIBE KEYSPACES
DESCRIBE KEYSPACE <keyspace name>
DESCRIBE TABLES
DESCRIBE TABLE <table name>
DESCRIBE INDEX <index name>
DESCRIBE MATERIALIZED VIEW <view name>
DESCRIBE TYPES
DESCRIBE TYPE <type name>
DESCRIBE FUNCTIONS
DESCRIBE FUNCTION <function name>
DESCRIBE AGGREGATES
DESCRIBE AGGREGATE <aggregate function name>

Example:

cqlsh> describe cluster
Cluster: Test Cluster
Partitioner: Murmur3Partitioner
cqlsh>

COPY TO – This command copies data from a table to a CSV file.

Syntax:

COPY <table name> [(<column>, ...)] TO <file name> WITH <copy option> [AND <copy option> ...]

 

Note:

If we need specific columns , then we need to specify the column list, Otherwise it will copy all columns from the table to the CSV file.