LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

cockroach

distributed SQL database CLI

TLDR

Start single-node cluster
$ cockroach start-single-node --insecure
copy
Start SQL shell
$ cockroach sql --insecure --host=[localhost]
copy
Execute SQL statement
$ cockroach sql --insecure -e "[SELECT * FROM users]"
copy
Initialize cluster
$ cockroach init --insecure --host=[localhost]
copy
Show node status
$ cockroach node status --insecure
copy
Create database
$ cockroach sql --insecure -e "CREATE DATABASE [mydb]"
copy
Import CSV data into a table
$ cockroach sql --insecure -e "IMPORT INTO [table] CSV DATA ('[file_url]')"
copy
Start a temporary demo cluster
$ cockroach demo
copy
Show cluster settings
$ cockroach sql --insecure -e "SHOW CLUSTER SETTINGS"
copy

SYNOPSIS

cockroach command [options]

DESCRIPTION

cockroach is the command-line interface for CockroachDB, a distributed SQL database designed for cloud-native applications. It provides comprehensive tools for managing multi-node clusters, executing SQL queries, performing backups and restores, and monitoring cluster health and performance.CockroachDB combines the scalability of NoSQL systems with the consistency guarantees and SQL interface of traditional relational databases. The CLI handles cluster initialization, node management, certificate generation for secure deployments, and direct SQL execution either interactively or programmatically.The tool supports both secure production deployments with TLS certificates and insecure development environments. It includes a demo mode for experimentation and testing without requiring persistent storage or cluster setup.

PARAMETERS

--insecure

Disable TLS (development only)
--host=address
Server address
--port=port
Server port (default: 26257)
--certs-dir=path
Certificate directory
--store=path
Data storage location
-e, --execute=sql
Execute SQL statement
--url=url
Connection URL
--log-dir=path
Directory for log files
--listen-addr=address
Address and port to listen on (default: localhost:26257)

COMMANDS

start

Start a CockroachDB node
start-single-node
Start single-node cluster
init
Initialize multi-node cluster
sql
Open SQL shell or execute statements
node
Manage cluster nodes
quit
Drain and shut down node
cert
Create CA, node, and client certificates
debug
Debugging commands for inspecting cluster state
workload
Generators for data and query loads (e.g., benchmarks)
nodelocal upload
Upload a file to a node's local file system
version
Show version
demo
Start temporary demo cluster

ENVIRONMENT

Flags can be set via environment variables: COCKROACHHOST, COCKROACHPORT, COCKROACHUSER, COCKROACHINSECURE

CAVEATS

Use --insecure only for development. Production requires TLS certificates. Compatible with PostgreSQL wire protocol.

SEE ALSO

psql(1), mysql(1), sqlite3(1)

Copied to clipboard
Kai