Connect to the CQL shell

The Cassandra Query Language Shell (CQLSH) is an interface that you can use to issue Cassandra Query Language (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

Each Astra DB Serverless database includes an embedded CQL shell instance.

  1. In the Astra Portal, create a database, if you don’t already have one.

  2. Go to Databases, and then select your database.

  3. 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 CQLSH client is a separate, lightweight tool you can use to interact with your database.

Prerequisites

Install the standalone CQLSH

  1. Download the CQLSH for your Astra DB Serverless database. Select the CQLSH for DataStax Astra or DataStax Astra with support for Vector Type.

  2. Change to the directory with the downloaded CQLSH tarball.

    $ cd /DOWNLOAD_DIRECTORY
  3. Extract the files from the tarball.

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

    Replace date with the date that the tarball was released, such as 20210304.

  4. Run the cqlsh script from the command line:

    $ cd /cqlsh-astra
    $ ./bin/cqlsh -u CLIENT_ID -p CLIENT_SECRET -b /SECURE_CONNECT_BUNDLE_PATH/secure-connect-DATABASE_NAME.zip

    Use the -b option to specify the location of the SCB for your database. Pass the CLIENT_ID and CLIENT_SECRET for your database role using the -u and -p options. For more, see Manage application tokens.

    CLIENT_ID

    Client ID for the database role.

    CLIENT_SECRET

    Client secret for the specified Client ID.

    database_name

    Name of the Astra DB database to which you want to connect. Include the absolute path to the SCB for the database, such as '/Users/myuser/Downloads/secure-connect-database123.zip'.

    Configure the cqlshrc file

    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

    You are connected to your database using CQLSH.

    [cqlsh 6.8.0 | DSE 6.8.0.77 | CQL spec 3.4.5 | DSE protocol v2]
    Use HELP for help.
    username@cqlsh>
  5. Switch to your keyspace, where you can issue CQL commands to create tables, insert data, and manage database resources:

    use KEYSPACE_NAME;

You can now query your database using CQL commands.

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