Apache Cassandra – Part 03 (cqlsh)

From previous two posts we talked about the basics and the installation of Apache Cassandra,

  1. Part 01 – Basics/ Introduction
  2. Part 02 – Installation

From this post I’m going to talk about the cqlsh, the terminal client for Cassandra. As we are using the mysql client to connect to the mysql server we have the cqlsh client to connect to the Cassandra server. We can find this at the /bin directory. Simply we can start the client service by executing the ./cqlsh. Also we can provide a user name and a password as parameters for the user whom we are going to logged in as.

./cqlsh -ucassandra -pcassandra

100.png

There are few shell commands which you might need to know for working with the terminal client. Let’s see them in detail,

00

  • HELP – Using the HELP command we can get a list of items which are documented in Cassandra.

1

  • HELP <key> – We can give one of the above mentioned keys with the HELP command to get a description about that command. Shell commands will be shown directly on the terminal, but the documentation for the CQL queries will be shown on a browser.

2

3

4

  • CLS – This command can be used to clear the terminal.

5

  • CLEAR – Similar to CLS

22

  • CAPTURE : Using the CAPTURE command we can get the terminal output of a CQL query to a specific file. In this example I’m getting the output of SELECT query to a file called cassandra.txt located at /home/vimukthi/. Using CAPTURE <path-to-file> we can turn on the capturing and using CAPTURE OFF we can turn off the feature.

7

8

9

  • CONSISTENCY : Using this command we can view the current consistency and also using CONSISTENCY <value> we can set a new value as well.

10

  • COPY : This is somewhat similar to the CAPTURE. But in CAPTURE we directly print the terminal output to a file. But using COPY we can get the output as a comma separated value list. Also we can source a comma separated list of values to a table using COPY as well.

11

12

  • DESCRIBE : we can get the definition of key space, tables, etc. Similar to desc in MySQL.
  • DESC : Short-hand format of DESCRIBE

14

  • EXPAND : Using this feature we can get the output in more detailed. This is similar to the \G in MySQL.

15

  • SHOW : Using SHOW <key> we can get information about Cassandra server, client, etc. For an example host, version, etc.

16

  • SOURCE : Using the SOURCE <path-to-file> we can execute CQL queries which are stored on a file.

17

18

  • LOGIN : Without exit from the current user, we can directly log in to another user through the terminal with this command. LOGIN -u<user-name> -p<password>

19

  • SERIAL : SERIAL CONSISTENCY will show the consistency level.

21

  • PAGING : This is the pagination support in terminal. PAGING will show the current status. Also we can set a level using PAGING <amount> as well. PAGING OFF will disable the feature.

paging.png

  • TRACING : TRACING ON will enable the feature and TRACING OFF will disable it.

24

25

  • EXIT : Same as MySQL, we can use EXIT command to exit from the client.

20

So from this post we talked about all the shell commands in Cassandra. Hope now you have a clear idea about the Cassandra shell, cqlsh. From the next post let’s talk about the Cassandra query language, CQL. Hope to see you soon with the next post, Thank You!

Advertisements

One thought on “Apache Cassandra – Part 03 (cqlsh)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s