Apache Cassandra is a free, open-source, distributed database system for managing large amounts of structured, semi-structured, and unstructured data. Cassandra is designed to scale to a very large size across many commodity servers with no single point of failure. Cassandra provides a powerful dynamic schema data model designed to allow for maximum flexibility and performance at scale.
Getting started with Cassandra is fast and easy. Installing Cassandra on a single machine is the best way to learn the basics. The following will help you install Cassandra and become familiar with some basic commands.
Before installing Cassandra on Linux, Windows, or Mac, ensure that you have the most up-to-date version of Java installed on your machine. To determine if Java is installed on your system, in a terminal window enter:
java -version
Download the DataStax Community Edition Server, which is a bundle containing the most up-to-date version of Cassandra along with all the utilities and tools you’ll need. You can also download directly from a terminal window wget on Linux or curl on Mac and the following URL:
http://downloads.datastax.com/community/dsc.tar.gz
On Windows, download and use the DataStax Windows MSI installer.
Note that DataStax also makes available RPM and Debian builds for Linux that are available on the main Download page.
On Linux or Mac, navigate to the bin directory and invoke the cassandra script:
sudo ./cassandra
On Windows, the Cassandra server starts running after installation.
Cassandra has a couple of interfaces that you can use to enter commands - the CLI and the CQL (Cassandra Query Language) utility. For this indroduction use the CLI, which in the Windows Cassandra group folder and in the bin directory on Linux or Mac:
./cassandra-cli -h localhost
A keyspace in Cassandra is the equivalent of a database in the RDBMS world. You can have multiple keyspaces on a Cassandra server.
First create a simple keyspace to work with:
[default@unknown] create keyspace mykeyspace;
[default@unknown] use mykeyspace;
A couple family is the primary data object in Cassandra, similar to a table in the RDBMS world. To create simple column family:
[default@mykeyspace] create column family cf1;
Now you can enter and read data from Cassandra.
To insert data:
[default@mykeyspace] set cf1[1]['c2']=utf8('test');
To read that data:
[default@mykeyspace] get cf1[1];
To update that data:
[default@mykeyspace] set cf1[1]['c2']=utf8('test2');
To delete that data:
[default@mykeyspace] del cf1[1];
To exit the CLI:
[default@mykeyspace] exit;