Connecting to databases using the CQL shell (CQLSH)

Configure CQLSH to log in to an Apollo database and run CQL commands.

Use the CQL shell (CQLSH) to connect to Apollo databases created using the DataStax Constellation console.
Tip: Alternatively, connect to your databases using DataStax Studio, which is automatically configured for interactive CQL commands. Use the predefined notebooks to learn CQL basics and start creating tables in your keyspace.

Prerequisites

  1. Download and install CQLSH. Choose the CQLSH version for the latest DSE version.
  2. Create a DataStax Apollo database.
  3. Download the secure connect bundle to obtain connection credentials for your database.

Procedure

  1. On the machine where you downloaded CQLSH, create a ~/.cassandra directory in your home directory.
    mkdir ~/.cassandra
    Important: Make sure to include the period in the directory name.
  2. Copy the secure connect bundle that you downloaded and place it in the ~/.cassandra directory.
    cp secure-connect-database_name.zip ~/.cassandra
  3. Unzip the secure connect bundle in the ~/.cassandra directory.
    cd ~/.cassandra
    unzip secure-connect-database_name.zip

    The cqlshrc file is included in the secure connect bundle. When you unzip the bundle, this file will be placed in your ~/.cassandra directory.

    Note: Only one cqlshrc file is supported per directory. The default directory for this file is ~/.cassandra.
    database_user
    User name for the database.
    database_password
    Password for the specified username.
  4. From the ~/.cassandra directory, connect to your database using CQLSH.
    cqlsh -u database_user -p database_password
    database_user
    User name for the database.
    database_password
    Password for the specified username.
    Connected to database_name at host_name:30003.
    [cqlsh 5.0.1 | DSE 6.8.0 | CQL spec 3.4.5 | DSE protocol v2]
    Use HELP for help.
    database_username@cqlsh:keyspace_name>

Results

You can now connect directly to the database using cqlsh.

Configuring the cqlshrc file

The cqlshrc file included in the secure connect bundle is preconfigured to work with your Apollo database. However, if you want to modify that file to connect to other databases, use the following example as guidance.

Configure the [ssl] section of the cqlshrc file in your ~/.cassandra directory to include the path to your connection credentials.

[connection]
hostname = database_endpoint
port = port_number
ssl = true

[ssl]
validate = true
certfile = ~/.cassandra/certificate.crt
userkey  = ~/.cassandra/private_RSA_key
usercert = ~/.cassandra/user_SSL_certificate

The following information is copied from the database Connection Details page in the DataStax Constellation console. Values for the database_endpoint and port_number are written to the cqlshrc file when you download database credentials.
database_endpoint
Endpoint for the database, such as database123.us-east-1.cloud.datastax.com.
port_number
Port number on the database used to connect to DSE.
certificate.crt
Location of the security certificate for the database, which uses a .crt extension.
private_RSA_key
Private RSA key for connecting to the indicated database.
user_SSL_certificate
SSL certificate for the indicated user.

What's next

See the following documentation to get started with CQL: