Tips to deploy Cassandra, the cloud friendly database

author-image
CIOL Bureau
Updated On
New Update

BANGALORE, INDIA: Cassandra was developed by Facebook and later open sourced in 2008. Eventually, Cassandra became an Apache project hosted at http://cassandra. apache.org/. It falls under a category of databases called NoSQL, which stands for Not Only SQL.

Advertisment

Such databases do not use the popular SQL (Structured Query Language) to create tables and insert, delete or update data. The expectation of a NoSQL database to have features found in RDBMS (Relational Database Management System) stretches the learning even further. In this article, we show you how typical RDBMS operations can be performed against a Cassandra database.

Installing Cassandra

For this article, we will install Cassandra on a machine running Fedora 13 Linux. While the Cassandra binary and source are available at http://cassandra.apache.org, we will install Cassandra via RPM. Login as root and issue the following commands to install Cassandra.

Advertisment

rpm-ivh http://rpm.riptano.com/Fedora/13/i386/riptano-release-5-3.fc13.noarch.rpm
yum install apache-cassandra

This will install Cassandra (version 0.7.1 as of this writing). The RPMs for other versions of Fedora, Redhat Enterprise Linux or CentOS are also available. Browse to the URL http://rpm.riptano.com/ to find these RPMs.

To start Cassandra, issue the following command:

Advertisment

service cassandra start

While it is considered inappropriate to map RDBMS concepts to a NoSQL database, it is still the quickest way to start learning the latter. While we will deal with querying Cassandra later in the article, in this section we will map the basic database objects to their look alikes in Cassandra.

A Keyspace contains one or more Column Families. A Column Family contains one or more Columns. To query Cassandra we use the cassandra-cli command line client which is installed by the RPM (see above). Open a terminal window or console and issue the following to run the client:

Advertisment

cassandra-cli

This will show the following output and drop you to a prompt to start querying Cassandra.

Welcome to cassandra CLI.
Type 'help;' or '?' for help. Type 'quit;' or 'exit;' to quit.

Advertisment

Here is the prompt from where you can start issuing statements to query Cassandra. To quit from this prompt issue:

quit;

Connecting to Cassandra

Advertisment

By default, Cassandra runs on port 9160. To connect to it, at the default@unknown prompt, issue the following:

connect localhost/9160;

This will produce an output saying - Connected to: "Test Cluster" on localhost/9160. In the following sections, we explain querying Cassandra along with example SQL (RDBMS) queries. We will use MySQL as the RDBMS. As explained above, a database is called a Keyspace. In MySQL, a database can be created as follows:

Advertisment

create database news;

To create a Keyspace in Cassandra, issue the following at the cassandra-cli prompt:

create keyspace news;

To drop a database:

drop database news; (SQL)
drop keyspace news; (Cassandra)

Click here to know more!

tech-news