← 返回命令列表

Linux command

cockroach 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Start single-node cluster

cockroach start-single-node --insecure

Start SQL shell

cockroach sql --insecure --host=[localhost]

Execute SQL statement

cockroach sql --insecure -e "[SELECT * FROM users]"

Initialize cluster

cockroach init --insecure --host=[localhost]

Show node status

cockroach node status --insecure

Create database

cockroach sql --insecure -e "CREATE DATABASE [mydb]"

Import CSV data into a table

cockroach sql --insecure -e "IMPORT INTO [table] CSV DATA ('[file_url]')"

Start a temporary demo cluster

cockroach demo

Show cluster settings

cockroach sql --insecure -e "SHOW CLUSTER SETTINGS"

说明

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.

参数

--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)

FAQ

What is the cockroach command used for?

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.

How do I run a basic cockroach example?

Run `cockroach start-single-node --insecure` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --insecure do in cockroach?

Disable TLS (development only)