Connect to the CQL shell

The Cassandra Query Language Shell (cqlsh) is a utility that you can use to issue CQL commands to your Astra DB Serverless database. You can use the embedded CQL shell in the Astra Portal or the standalone CQL shell.

You can use the Astra CLI to download and configure the CQL shell, including the Secure Connect Bundle (SCB) and set up the token for your Astra DB Serverless account. For more information, see the Use cqlsh in the Astra CLI documentation.

Embedded CQL shell

The Astra Portal provides an embedded CQL shell instance, known as the CQL Console, for each Astra DB Serverless database.

  1. In the Astra Portal navigation menu, select your database.

  2. Click CQL Console.

The CQL Console opens in a new window and connects directly to your database. You can now run CQL commands on your database without leaving your browser.

Standalone CQL shell

The standalone CQL shell client is a separate, lightweight utility that you can use to interact with your database.

To install and use the standalone CQL shell, you need Python version 2.7.12+ with TLS Support and the SCB for your database.

  1. Download the CQL shell for your Astra DB Serverless database:

    • DataStax Astra

    • DataStax Astra with support for Vector Type.

  2. Change to the directory where you downloaded the CQL shell package:

    $ cd /DOWNLOAD_DIRECTORY
  3. Extract the files:

    $ tar -xvf cqlsh-astra-DATE-bin.tar.gz

    Replace date with the package release date, such as 20210304.

  4. Run the cqlsh script:

    $ cd /cqlsh-astra
    $ ./bin/cqlsh -u CLIENT_ID -p CLIENT_SECRET -b PATH_TO_SCB

    Specify the following arguments:

    • -b: The path to your database’s SCB (secure-connect-DATABASE_NAME.zip).

    • -u and -p: Authentication credentials to connect to your database. Either a CLIENT_ID and CLIENT_SECRET or the literal string token and an application token prefixed by AstraCS:. For more information, see Manage application tokens.

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

      In the [authentication] section of the cqlshrc file in ~/.cassandra, include the CLIENT_ID and CLIENT_SECRET from your application token. Configure the [connection] section of the cqlshrc file in ~/.cassandra to include the path to your SCB:

      [authentication]
      username = CLIENT_ID
      password = CLIENT_SECRET
      
      [connection]
      secure_connect_bundle = /SECURE_CONNECT_BUNDLE_PATH/secure-connect-DATABASE_NAME.zip

      A result such as the following indicates that the CQL shell is connected to your database:

      [cqlsh 6.8.0 | DSE 6.8.0.77 | CQL spec 3.4.5 | DSE protocol v2]
      Use HELP for help.
      username@cqlsh>
  5. To manage data, select the keyspace that you want to work in:

    use KEYSPACE_NAME;

From here, you can issue any supported CQL commands to create tables, insert data, update data, and more. For more information, see Cassandra Query Language (CQL) for Astra DB quickstart and CQL reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com