Connecting to Astra databases using CQLSH

Use CQLSH to interact with your database through CQL commands.

The Cassandra Query Language SHell (CQLSH) is a command line shell for interacting with your database through Cassandra Query Language (CQL). This tool provides a useful interface for accessing the database and issuing CQL commands.

Embedded connection

Each DataStax Astra database includes an embedded CQLSH instance. In the DataStax Cloud console, navigate to your database and click the CQL Console tab to open a CQLSH instance that is connected to your database. Issue CQL commands directly to your Astra database without navigating outside of your browser.

Tip: To see the CQL console in a full browser window, use this URL format: database_id-region.apps.astra.datastax.com/cqlsh

For example, 2f0c6j8b-9790-4276-a16c-0cd7b055344a-us-east1.apps.astra.datastax.com/cqlsh.

Peripheral connection

Alternatively, you can connect to your Astra database using the standalone version of CQLSH.

Connecting to databases using standalone CQLSH

Use the standalone CQLSH tool to interact with your database through CQL commands.

The Cassandra Query Language SHell (CQLSH) is a command line shell for interacting with your database through Cassandra Query Language (CQL). This tool provides a useful interface for accessing the database and issuing CQL commands.

Instead of using the native CQL shell that is included in DataStax Enterprise (DSE) or DataStax Distribution of Apache Cassandra (DDAC), the standalone CQLSH client is a separate, lightweight tool you can use to interact with your database.

Tip: Each DataStax Astra database includes an embedded CQLSH instance. In the DataStax Cloud console, navigate to your database and click the CQL Console tab to open a CQLSH instance that is connected to your database.

Prerequisites

  1. Download CQLSH. Choose the version for DataStax Astra.
  2. Create a DataStax Astra database.
  3. Download the secure connect bundle to obtain connection credentials for your DataStax Astra database.

Procedure

  1. Change to the directory where you downloaded the CQLSH tarball and then extract it.
    cd /download_directory
    tar -xvf cqlsh-astra-date-bin.tar.gz

    date is the date that the tarball was released, such as 20200120.

  2. From the directory where you extracted the CQLSH tarball, run the cqlsh script from the command line.

    Use the -b option to specify the location of the secure connect bundle that you downloaded for your database. Pass the username and password for the database using the -u and -p options.

    cd /cqlsh-astra
    ./bin/cqlsh -u username -p password -b /path/to/secure-connectdatabase_name.zip
    username
    Username for the database.
    password
    Password for the specified username.
    database_name
    Name of the Astra database you want to connect to. Include the absolute path to the secure connect bundle for the database, such as /Users/myuser/Downloads/secure-connect-database123.zip.

Results

You are connected directly to your Astra database using CQLSH.
Connected to caas-cluster at host_name:9042.
[cqlsh 6.8.0 | DSE 6.8.0.77 | CQL spec 3.4.5 | DSE protocol v2]
Use HELP for help.
username@cqlsh>

Explore your keyspaces

To view all available keyspaces, run the following command:

DESCRIBE KEYSPACES;

View the keyspace that you created for your Astra database:

DESCRIBE KEYSPACE my_keyspace;

Configuring the cqlshrc file

If you do not want to pass the secure connect bundle on the command line every time, set up the location in your cqlshrc file.

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

[connection]
secure_connect_bundle = /path/to/secure-connect-database_name.zip

What's next

See the following documentation to get started with CQL:

Switch to your keyspace, where you can issue CQL commands to create tables, insert data, and manage database resources:

USE my_keyspace;