Show Menu

Apache Cassandra CQL Cheat Sheet by

My most common CQLs for developing and administrating

Symbolic Link to an Encrypted LVM Volume

ls -lrtah /var/lib/cassandra
lrwxrwxrwx 1 cassandra cassandra 34 Sep  9 19:13 /var/lib/cassandra -> /media/SecureDataStore/cassandra
sudo chown -R cassandra:cassandra /var/lib/cassandra
sudo chown -R cassandra:cassandra /media/SecureDataStore/cassandra

Logging Into CQLSH

export CQLSH_HOST=<rpc address>
export CQLSH_PORT=9042
cqlsh -u cassandra
cassandra@cqlsh> exit

Creating DB Users, Roles, and Access

CREATE ROLE supervisor;
GRANT MODIFY ON warehouse.orders TO supervisor;
GRANT SELECT ON warehouse.addresses TO supervisor;

CREATE ROLE bob WITH PASSWORD = 'password' AND LOGIN = true;
GRANT supervisor TO bob;


CREATE ROLE office_admin;
GRANT SELECT ON KEYSPACE office TO office_admin;
GRANT MODIFY ON KEYSPACE office TO office_admin;
GRANT office_admin TO bob;

REVOKE MODIFY ON KEYSPACE office TO office_admin;

Exploring Key Spaces and Tables

DESCRIBE keypsaces;
USE <yourkeyspace>;
DESCRIBE tables;

Minimum Dev Config­uration

sudo nano /etc/cassandra/cassandra.yaml
cluster_name: 'Name of Cluster'
rpc_address: <Your IP. Do not use a FQDN>
authenticator: PasswordAuthenticator

sudo chmod 777 /etc/security/limits.conf
echo "* -       memlock unlimited" >> /etc/security/limits.conf
echo "* -       nofile  100000" >> /etc/security/limits.conf
echo "* -       nproc   32768" >> /etc/security/limits.conf
echo "* -       as      unlimited" >> /etc/security/limits.conf
sudo chmod 644 /etc/security/limits.conf

Start Stop Service

sudo -u cassandra cassandra
ps -ef | grep cassandra
sudo kill -9 <PID of cassandra>

Python Batch Inserts

from cassandra.auth import PlainTextAuthProvider
from cassandra.cluster import Cluster
from cassandra.query import BatchStatement
auth_provider_omni = PlainTextAuthProvider(
cluster_omni = Cluster(
    # ssl_options=ssl_opts
conn = self.cluster_omni.connect(

batch = BatchStatement()
sql_str = (
                'INSERT INTO ' + TABLE_PREFIX + '_' +
                location.lower() + '_' +
                demographic.lower() +
                ' (date,value) VALUES (?,?)'
sql = conn.prepare(sql_str)
for value in values:
    batch.add(sql, value['date'], value['value'])


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Selenium WebDriver Cheat Sheet Cheat Sheet
          Cypressio Cheat Sheet
          ISTQB Test Automation Engineering Cheat Sheet

          More Cheat Sheets by edendekker

          Jenkins CLI Cheat Sheet
          VIM Cheat Sheet Cheat Sheet