ycqlsh is the command-line shell for interacting with YugabyteDB using the YCQL API (Cassandra-compatible).
Synopsis
Description
ycqlsh is a Python-based command-line interface for interacting with YugabyteDB using YCQL (Yugabyte Cloud Query Language). It provides:- Interactive CQL query execution
- Data import/export capabilities
- Cluster administration commands
- Scriptable operations
Requirements
Python 3.6 or later must be installed.Installation
ycqlsh is installed with YugabyteDB and located in thebin directory. A standalone version is also available through the YugabyteDB clients package.
Default Connection Parameters
- Host:
127.0.0.1(localhost) - Port:
9042 - Username: Not required for insecure clusters
Starting ycqlsh
Command-Line Flags
Connection Flags
-u, —user=USERNAME
Username to authenticate with.-p, —password=PASSWORD
Password to authenticate with.-k, —keyspace=KEYSPACE
Authenticate to a specific keyspace.—ssl
Use SSL when connecting to YugabyteDB.Query Execution Flags
-e, —execute=STATEMENT
Execute a single CQL statement and exit.-f, —file=FILENAME
Execute CQL commands from a file and exit.Output Formatting Flags
-C, —color
Force color output.—no-color
Disable color output.—browser=BROWSER
Specify browser for displaying help.Connection Options
—connect-timeout=SECONDS
Connection timeout in seconds (default: 2).—request-timeout=SECONDS
Request timeout in seconds (default: 10).Behavior Flags
-t, —tty
Force TTY mode (command prompt).—debug
Print additional debugging information.—encoding=ENCODING
Specify output encoding (default: UTF-8).—cqlshrc=FILE
Specify location of cqlshrc configuration file.~/.cassandra/cqlshrc
-r, —refresh_on_describe
Force refresh of schema metadata on DESCRIBE commands.Special Commands
In addition to CQL statements, ycqlsh supports special commands:CAPTURE
Capture command output to a file.CLEAR / CLS
Clear the console.CONSISTENCY
Set or view consistency level for read operations.QUORUM: Read from tablet leader with strong consistency (default)ONE: Read from follower with relaxed consistency
COPY FROM
Import data from CSV file to table.| Flag | Default | Description |
|---|---|---|
INGESTRATE | 100000 | Max rows per second |
MAXROWS | -1 | Max rows to import (-1 = unlimited) |
SKIPROWS | 0 | Number of initial rows to skip |
SKIPCOLS | Comma-separated columns to ignore | |
MAXPARSEERRORS | -1 | Max parsing errors (-1 = unlimited) |
MAXINSERTERRORS | 1000 | Max insert errors (-1 = unlimited) |
ERRFILE | File to store failed rows | |
MAXBATCHSIZE | 20 | Max rows per batch |
MINBATCHSIZE | 2 | Min rows per batch |
CHUNKSIZE | 1000 | Rows passed to workers at a time |
COPY TO
Export data from table to CSV file.| Flag | Default | Description |
|---|---|---|
MAXREQUESTS | 6 | Max token ranges to fetch simultaneously |
PAGESIZE | 1000 | Rows to fetch in a single page |
PAGETIMEOUT | 10 | Timeout in seconds per 1000 entries |
BEGINTOKEN | Start token for export range | |
ENDTOKEN | End token for export range | |
MAXOUTPUTSIZE | -1 | Max output file lines (-1 = unlimited) |
ENCODING | utf8 | Character encoding |
| Flag | Default | Description |
|---|---|---|
NULLVAL | null | String placeholder for null values |
HEADER | false | Include column headers |
DELIMITER | , | Field delimiter |
QUOTE | ” | Quote character |
ESCAPE | \ | Escape character |
NUMPROCESSES | Number of worker processes |
DESCRIBE / DESC
Describe database objects.EXPAND / NOEXPAND
Toggle expanded output format.EXIT / QUIT
Exit ycqlsh.HELP
Display help information.PAGING
Control result paging.SHOW
Show current session settings.SOURCE
Execute commands from a file.TRACING
Enable or disable query tracing.Common Usage Examples
Connect to Cluster
Execute Queries
Create Keyspace and Table
Import/Export Data
Save Query Results
Batch Operations
Schema Management
Interactive Mode
When started without-e or -f, ycqlsh enters interactive mode:
- Command history (arrow keys)
- Tab completion for keywords and table names
- Multi-line statement editing
- Color-coded output
Configuration File
Create~/.cassandra/cqlshrc to customize ycqlsh:
Environment Variables
| Variable | Description |
|---|---|
CQLSH_HOST | Default host to connect to |
CQLSH_PORT | Default port to connect to |
CQLSH_NO_BUNDLED | Use system Python packages |
Output Examples
Standard Output
Expanded Output
CSV Output
Security Considerations
-
Password Security: Don’t use
-pflag with password in scripts. Use.cassandra/cqlshrcwith proper permissions: -
SSL Connections: Use
--sslflag for encrypted connections. -
Command History: Sensitive data may be stored in
~/.cassandra/cqlsh_history. Clear if needed:

