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
No. | Command | Description |
---|
1 | CREATE USER username WITH PASSWORD 'password'; | Create a new user. |
2 | ALTER USER username WITH PASSWORD 'new_password'; | Change a user’s password. |
3 | DROP USER username; | Remove a user from the system. |
4 | LIST USERS; | List all users with their roles. |
5 | LIST ROLES; | List all roles defined in the system. |
6 | CREATE ROLE role_name; | Create a new role. |
7 | ALTER ROLE role_name WITH SUPERUSER = true; | Grant superuser status to a role. |
8 | DROP ROLE role_name; | Remove a role from the system. |
Keyspace and Table Management
No. | Command | Description |
---|
1 | DESCRIBE KEYSPACES; | List all keyspaces in the cluster. |
2 | USE keyspace_name; | Switch to a specific keyspace. |
3 | DESCRIBE TABLES; | List all tables in the current keyspace. |
4 | CREATE KEYSPACE keyspace_name WITH ...; | Create a new keyspace with specified options. |
5 | CREATE TABLE table_name (col1 TYPE, ...); | Create a new table with specified columns. |
6 | INSERT INTO table_name ... VALUES (...); | Insert data into a table. |
7 | SELECT * FROM table_name; | Retrieve all rows from a table. |
8 | UPDATE table_name SET col1 = ... WHERE ...; | Update data in a table. |
9 | DELETE FROM table_name WHERE ...; | Delete data from a table. |
10 | ALTER TABLE table_name ...; | Modify the structure of a table. |
11 | DROP KEYSPACE keyspace_name; | Remove a keyspace and its data. |
12 | DROP TABLE table_name; | Remove a table and its data. |
Cluster Management
No. | Command | Description |
---|
1 | DESCRIBE CLUSTER; | Display information about the Cassandra cluster. |
2 | NODETOOL STATUS; | Show status of the nodes in the cluster. |
3 | NODETOOL INFO; | Display information about the Cassandra node. |
4 | NODETOOL REPAIR; | Trigger a manual repair of data inconsistencies. |
5 | NODETOOL FLUSH; | Flush data from memtables to disk. |
6 | NODETOOL CLEAN; | Run cleanup on a node. |
7 | NODETOOL REBUILD; | Rebuild data on a node. |
8 | NODETOOL DISABLEGOSSIP; | Disable gossip (used for maintenance). |
9 | NODETOOL ENABLEGOSSIP; | Re-enable gossip after disabling. |
10 | NODETOOL DISABLETHRIFT; | Disable Thrift server. |
11 | NODETOOL ENABLETHRIFT; | Re-enable Thrift server. |
No. | Command | Description |
---|
1 | CQL TRACING ON; | Enable tracing for CQL queries. |
2 | SELECT COUNT(*) FROM table_name; | Count the number of rows in a table. |
3 | DESCRIBE REPLICATION FOR keyspace.table; | View replication details for a specific table. |
4 | DESCRIBE INDEX index_name; | View information about a secondary index. |
5 | CREATE INDEX index_name ON table_name (...); | Create a secondary index on a table. |
6 | DROP INDEX index_name; | Remove a secondary index from a table. |
7 | DESCRIBE FULL SCHEMA; | Display detailed schema information. |
Data Import and Export
No. | Command | Description |
---|
1 | COPY table_name TO 'file.csv' WITH ...; | Export data from a table to a CSV file. |
2 | COPY table_name FROM 'file.csv' WITH ...; | Import data into a table from a CSV file. |
Security and Permissions
No. | Command | Description |
---|
1 | GRANT PERMISSIONS ON keyspace_name TO user; | Grant permissions on a keyspace to a user. |
2 | REVOKE PERMISSIONS ON keyspace_name FROM user; | Revoke permissions on a keyspace from a user. |
3 | LIST ALL PERMISSIONS ON keyspace_name; | List all permissions on a keyspace. |
Miscellaneous
No. | Command | Description |
---|
1 | SHOW VERSION; | Display the Cassandra version. |
2 | DESCRIBE HANDOFFS; | Display information about pending hints handoff. |
3 | DESCRIBE HINTEDHANDOFF; | View details about hinted handoff settings. |
4 | DESCRIBE COMPACTIONS; | Display details about ongoing compactions. |
5 | DESCRIBE PENDING COMPACTIONS; | View pending compactions. |
6 | DESCRIBE PENDING RANGES; | Display details about pending ranges. |
7 | DESCRIBE SCHEMAS; | Display all available schema versions. |
8 | TRUNCATE TABLE table_name; | Remove all data from a table. |
9 | SHOW HOST; | Display the current host’s information. |
10 | SHOW SESSION; | Display details about the current CQL session. |
11 | SHOW TRACING; | Display details about the current tracing session. |