Welcome to the World of NoSQL Databases
Linux | macOS | Windows
What is Apache Cassandra?
Apache Cassandra is a highly popular, free, and open-source NoSQL database. Unlike traditional relational databases that use tables with strict rules, Cassandra is designed to handle massive amounts of data across many different servers. It is built to be extremely fast and reliable, making it a top choice for big companies that cannot afford for their websites or apps to go offline.
The secret to Cassandra's power is its "distributed" design. Instead of keeping all your data in one central location, Cassandra spreads the data out across multiple machines, known as a cluster. Because there is no single master computer controlling everything, there is no single point of failure. If one machine breaks down, the other machines step in and keep the database running smoothly without losing any information.
Finally, Cassandra is built for amazing scalability. If your app becomes popular and you need to store more data, you can simply add more computers to the Cassandra cluster, and it will handle the extra workload automatically. To interact with the database, you use a language called Cassandra Query Language (CQL), which looks and feels very similar to traditional SQL, making it easy for beginners to learn and use.
Prerequisites
- Docker Installed: You must have Docker Desktop installed and running on your computer (available for Mac, Windows, or Linux).
- Command Line Knowledge: You need a basic understanding of how to use your computer's terminal or command prompt.
- Text Editor: A simple text editor (like Notepad, TextEdit, or VS Code) to create a database script file.
- Internet Connection: Required to download the necessary Docker images from Docker Hub.
Step-by-Step Installation and Setup
Get Cassandra Using Docker
docker pull cassandra:latest
Start Cassandra
docker network create cassandra docker run --rm -d --name cassandra --hostname cassandra --network cassandra cassandra
Create the Database File
data.cql . Open it in your text editor, paste the following code into it, and save the file. This script creates a storage area (keyspace), creates a table for a shopping cart, and adds two items to it.
-- Create a keyspace
CREATE KEYSPACE IF NOT EXISTS store WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : '1' };
-- Create a table
CREATE TABLE IF NOT EXISTS store.shopping_cart (
userid text PRIMARY KEY,
item_count int,
last_update_timestamp timestamp
);
-- Insert some data
INSERT INTO store.shopping_cart
(userid, item_count, last_update_timestamp)
VALUES ('9876', 2, toTimeStamp(now()));
INSERT INTO store.shopping_cart
(userid, item_count, last_update_timestamp)
VALUES ('1234', 5, toTimeStamp(now()));
Load Data into Cassandra
data.cql file you just created into your running database. This uses a tool called cqlsh (Cassandra Query Language Shell).
docker run --rm --network cassandra -v "$(pwd)/data.cql:/scripts/data.cql" -e CQLSH_HOST=cassandra -e CQLSH_PORT=9042 -e CQLVERSION=3.4.7 nuvo/docker-cqlsh
Access the Interactive Command Shell
docker run --rm -it --network cassandra nuvo/docker-cqlsh cqlsh cassandra 9042 --cqlversion='3.4.7'
cqlsh> prompt appear on your screen.
Read Your Data
SELECT * FROM store.shopping_cart;
Write More Data
INSERT INTO store.shopping_cart (userid, item_count) VALUES ('4567', 20);
Clean Up
exit to leave the shell, and then running these commands in your normal terminal:
docker kill cassandra docker network rm cassandra
CTCservers Recommended Tutorials
Web, Network
Step-by-Step Guide: Install AMD ROCm on Ubuntu with RX 6600 GPU
Learn how to quickly and easily set up AMD ROCm on Ubuntu for your RX 6600 GPU, enabling powerful machine learning, AI workloads, and GPU-accelerated computing right on your system.
Web, Network, Linux, Mysql, Ubuntu
LAMP Setup Guide 2026: Ubuntu & Debian | CTCservers
Install a secure LAMP stack on Debian or Ubuntu. Follow our step-by-step guide to configure Linux, Apache, MySQL, and PHP for your web server.
Web, Network, Ubuntu
Deploy Phi-3 with Ollama on Ubuntu GPU | CTCservers
Learn how to easily deploy the Phi-3 LLM on an Ubuntu 24.04 GPU server using Ollama and WebUI. Follow our step-by-step tutorial for seamless AI hosting.
Discover CTCservers Dedicated Server Locations
CTCservers servers are available around the world, providing diverse options for hosting websites. Each region offers unique advantages, making it easier to choose a location that best suits your specific hosting needs.