Getting Started
Thecockroach binary provides all CLI functionality through subcommands:
Run
cockroach help to see all available commands and cockroach [command] --help for detailed information about a specific command.Core Commands
Server Operations
| Command | Description |
|---|---|
start | Start a node in a multi-node cluster |
start-single-node | Start a single-node cluster |
init | Initialize a cluster |
Client Operations
| Command | Description |
|---|---|
sql | Open an interactive SQL shell |
node | List, inspect, drain, or remove nodes |
quit | Drain and shutdown a node |
Administrative Operations
| Command | Description |
|---|---|
debug | Debugging tools for troubleshooting |
gen | Generate auxiliary files (certificates, docs, etc.) |
version | Display version information |
Common Patterns
Connecting to a Cluster
All client commands support standard connection flags:Common Flags
These flags are available across most commands:Database server host and port. Can be specified as hostname or IP address.
Path to certificate directory for secure connections.
Connect without encryption (not recommended for production).
Database user name.
Full connection URL (alternative to individual connection flags).
Environment Variables
Many CLI flags can be set via environment variables:| Environment Variable | Corresponding Flag |
|---|---|
COCKROACH_HOST | --host |
COCKROACH_PORT | --port |
COCKROACH_DATABASE | --database |
COCKROACH_USER | --user |
COCKROACH_URL | --url |
Exit Codes
The CLI uses standard exit codes:- 0: Success
- 1: General error
- 2: Command-line parsing error
- 3: Connection error
- Specific codes: See individual command documentation
Security Best Practices
Always use secure connections in production:
- Generate certificates using
cockroach cert - Use
--certs-dirto specify certificate location - Never use
--insecurein production environments - Protect private keys with appropriate file permissions
Shell Completion
Enable command completion for your shell:- Bash
- Zsh
- Fish