Cassandra Cheat Sheet

Apache Cassandra is a powerful NoSQL database system known for its scalability and fault tolerance. This cheatsheet provides quick reference commands grouped by categories for common Cassandra operations.

User Management

1CREATE USER username WITH PASSWORD 'password';Create a new user.
2ALTER USER username WITH PASSWORD 'new_password';Change a user’s password.
3DROP USER username;Remove a user from the system.
4LIST USERS;List all users with their roles.
5LIST ROLES;List all roles defined in the system.
6CREATE ROLE role_name;Create a new role.
7ALTER ROLE role_name WITH SUPERUSER = true;Grant superuser status to a role.
8DROP ROLE role_name;Remove a role from the system.

Keyspace and Table Management

1DESCRIBE KEYSPACES;List all keyspaces in the cluster.
2USE keyspace_name;Switch to a specific keyspace.
3DESCRIBE TABLES;List all tables in the current keyspace.
4CREATE KEYSPACE keyspace_name WITH ...;Create a new keyspace with specified options.
5CREATE TABLE table_name (col1 TYPE, ...);Create a new table with specified columns.
6INSERT INTO table_name ... VALUES (...);Insert data into a table.
7SELECT * FROM table_name;Retrieve all rows from a table.
8UPDATE table_name SET col1 = ... WHERE ...;Update data in a table.
9DELETE FROM table_name WHERE ...;Delete data from a table.
10ALTER TABLE table_name ...;Modify the structure of a table.
11DROP KEYSPACE keyspace_name;Remove a keyspace and its data.
12DROP TABLE table_name;Remove a table and its data.

Cluster Management

1DESCRIBE CLUSTER;Display information about the Cassandra cluster.
2NODETOOL STATUS;Show status of the nodes in the cluster.
3NODETOOL INFO;Display information about the Cassandra node.
4NODETOOL REPAIR;Trigger a manual repair of data inconsistencies.
5NODETOOL FLUSH;Flush data from memtables to disk.
6NODETOOL CLEAN;Run cleanup on a node.
7NODETOOL REBUILD;Rebuild data on a node.
8NODETOOL DISABLEGOSSIP;Disable gossip (used for maintenance).
9NODETOOL ENABLEGOSSIP;Re-enable gossip after disabling.
10NODETOOL DISABLETHRIFT;Disable Thrift server.
11NODETOOL ENABLETHRIFT;Re-enable Thrift server.

Query and Performance

1CQL TRACING ON;Enable tracing for CQL queries.
2SELECT COUNT(*) FROM table_name;Count the number of rows in a table.
3DESCRIBE REPLICATION FOR keyspace.table;View replication details for a specific table.
4DESCRIBE INDEX index_name;View information about a secondary index.
5CREATE INDEX index_name ON table_name (...);Create a secondary index on a table.
6DROP INDEX index_name;Remove a secondary index from a table.
7DESCRIBE FULL SCHEMA;Display detailed schema information.

Data Import and Export

1COPY table_name TO 'file.csv' WITH ...;Export data from a table to a CSV file.
2COPY table_name FROM 'file.csv' WITH ...;Import data into a table from a CSV file.

Security and Permissions

1GRANT PERMISSIONS ON keyspace_name TO user;Grant permissions on a keyspace to a user.
2REVOKE PERMISSIONS ON keyspace_name FROM user;Revoke permissions on a keyspace from a user.
3LIST ALL PERMISSIONS ON keyspace_name;List all permissions on a keyspace.


1SHOW VERSION;Display the Cassandra version.
2DESCRIBE HANDOFFS;Display information about pending hints handoff.
3DESCRIBE HINTEDHANDOFF;View details about hinted handoff settings.
4DESCRIBE COMPACTIONS;Display details about ongoing compactions.
5DESCRIBE PENDING COMPACTIONS;View pending compactions.
6DESCRIBE PENDING RANGES;Display details about pending ranges.
7DESCRIBE SCHEMAS;Display all available schema versions.
8TRUNCATE TABLE table_name;Remove all data from a table.
9SHOW HOST;Display the current host’s information.
10SHOW SESSION;Display details about the current CQL session.
11SHOW TRACING;Display details about the current tracing session.