Apache Cassandra NoSql Database – Part 2

Introduction

This is the second tutorial of the Cassandra NoSql Database Series. In upcoming series, we will be discussing Cassandra Database Administration, Multi Node Cluster Management etc.

In First Part of Cassandra NoSQL Data base Series, we configure Apache Cassandra with Ubuntu 15.04 Desktop. In this second part, we will understand how to utilize ‘cqlsh’ Cassandra utility, ‘cqlsh’ is can be compared as mysql command utility for mysql database, this is not required that all of the rows must have the same no. of columns.

cqlsh Utility

As we have learned in previous tutorial that to utilize Apache Cassandra database we have to run $bin/cassandra -f command and leave it as such.

Open $bin/.cqlsh.

$bin/./cqlsh

Type help, this will display all of the available option with cqlsh utility.

cqlsh> help;

Ubuntu [Running] - Oracle VM VirtualBox_022

If you wants to get help for and command type help <command>;

cqlsh>help APPLY;

Selection_023

The show host utility will dump the cluster connected right now along with connected port information.

cqlsh>show host;

Selection_024

The show version utility will display installed version of cqlsh.

 cqlsh>show version;

‘describe keyspace’ command will display default and user created keyspaces (data base in terms of MySql).

cqlsh>describe keyspaces;

Selection_026

Let’s Create a new keyspace(database) and put some entries, no need to be panic <tab> will auto complete your commands, in below scenario  ‘example’ is the keyspace name (database name), ‘SimpleStrategy’ is used for a single data center, if you are using more then one data center then you will define ‘NetworkTopologyStrategy’ , ‘replication_factor’ is required if class is ‘SimpleStrategy’ otherwise not required.

cqlsh>create keyspace example with replication = {'class': 'SimpleStrategy', 'replication_factor':1};

Selection_027

Let’s have a look on newly created keyspace with ‘describe kespace’ command.

Selection_028

To delete any keyspace  use ‘drop’ command along with keyspace name (see the snapshot).

cqlsh>drop keyspace example;

Selection_029

Let’s put some entries in newly created keyspace named ‘example’.

cqlsh>use example;
cqlsh>create table unixmen_example (id bigint, username text, fname text, lname text, primary key (username) );

Selection_030

Have a look on field which you have just created in unixmen_example.

 cqlsh>select * from unixmen_example;

Selection_031

Let’s Put some Entries in newly created table.

cqlsh>insert into example (username, fname, lname) Values ('rajneesh@unixmen.com', 'rajneesh', 'upadhyay');

Reprint the entered Values.

 cqlsh>select * from unixmen_example;

Selection_032

Ok, This time we will define id to the user in next entry.

cqlsh>insert into example.unixmen_example (username, id, fname, lname) Values ('rajneesh@unixmen.com', 'rajneesh', 101, 'upadhyay');

Selection_033

What if we wants to see only two values in the output.

cqlsh>select fname, id from example.unixmen_example;

Selection_034

Have Fun!