From previous two posts we talked about the basics and the installation of Apache Cassandra,
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
There are few shell commands which you might need to know for working with the terminal client. Let’s see them in detail,
- HELP – Using the HELP command we can get a list of items which are documented in Cassandra.
- 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.
- CLS – This command can be used to clear the terminal.
- CLEAR – Similar to CLS
- 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.
- CONSISTENCY : Using this command we can view the current consistency and also using CONSISTENCY <value> we can set a new value as well.
- 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.
- DESCRIBE : we can get the definition of key space, tables, etc. Similar to desc in MySQL.
- DESC : Short-hand format of DESCRIBE
- EXPAND : Using this feature we can get the output in more detailed. This is similar to the \G in MySQL.
- SHOW : Using SHOW <key> we can get information about Cassandra server, client, etc. For an example host, version, etc.
- SOURCE : Using the SOURCE <path-to-file> we can execute CQL queries which are stored on a file.
- 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>
- SERIAL : SERIAL CONSISTENCY will show the consistency level.
- 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.
- TRACING : TRACING ON will enable the feature and TRACING OFF will disable it.
- EXIT : Same as MySQL, we can use EXIT command to exit from the client.
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!