Example of creating a keyspace

A simple example of querying Cassandra by creating a keyspace and then using it.

To query Cassandra, create and use a keyspace. Choose an arbitrary data center name and register the name in the properties file of the snitch. Alternatively, in a cluster in a single data center, use the default data center name, for example, datacenter1, and skip registering the name in the properties file.


  1. Determine the default data center name, if using NetworkTopologyStrategy, using nodetool status.
    bin/nodetool status

    The output is:

    Datacenter: datacenter1
    |/ State=Normal/Leaving/Joining/Moving
    --  Address    Load       Tokens  Owns (effective)  Host ID      Rack
    UN  41.62 KB   256     100.0%            75dcca8f...  rack1
  2. Create a keyspace.
    cqlsh> CREATE KEYSPACE IF NOT EXISTS cycling WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'datacenter1' : 3 };
  3. Use the keyspace.
    cqlsh> USE cycling;