CRDB(CockroachDB)初体验

  |   0 评论   |   613 浏览

背景

简单使用

下载

https://www.cockroachlabs.com

解压后是单个文件:cockroach

注:cockroach上传匿名使用数据到Cockroach Labs

启动

[abeffect@note cockroach-v2.0.1.darwin-10.9-amd64]$ ./cockroach start --insecure --host=localhost
*
* WARNING: RUNNING IN INSECURE MODE!
*
* - Your cluster is open for any client that can access localhost.
* - Any user, even root, can log in without providing a password.
* - Any user, connecting as root, can read or write any data in your cluster.
* - There is no network encryption nor authentication, and thus no confidentiality.
*
* Check out how to secure your cluster: https://www.cockroachlabs.com/docs/v2.0/secure-a-cluster.html
*
CockroachDB node starting at 2018-05-18 08:01:33.600136465 +0000 UTC (took 0.4s)
build:               CCL v2.0.1 @ 2018/04/23 18:35:36 (go1.10)
admin:               http://localhost:8080
sql:                 postgresql://root@localhost:26257?sslmode=disable
logs:                /Users/abeffect/share/cockroachdb/cockroach-v2.0.1.darwin-10.9-amd64/cockroach-data/logs
temp dir:            /Users/abeffect/share/cockroachdb/cockroach-v2.0.1.darwin-10.9-amd64/cockroach-data/cockroach-temp211438474
external I/O path:   /Users/abeffect/share/cockroachdb/cockroach-v2.0.1.darwin-10.9-amd64/cockroach-data/extern
store[0]:            path=/Users/abeffect/share/cockroachdb/cockroach-v2.0.1.darwin-10.9-amd64/cockroach-data
status:              initialized new cluster
clusterID:           a0ef8e47-5152-4836-bcb4-ad6261c9a1a6
nodeID:              1

Web页面

http://localhost:8080/

本地模拟集群

新打开两个终端,再依次启动两个节点

./cockroach start --insecure --store=node2 --host=localhost --port=26258 --http-port=8081 --join=localhost:26257

./cockroach start --insecure --store=node3 --host=localhost --port=26259 --http-port=8082 --join=localhost:26257

SQL使用

连接

./cockroach sql --insecure
# Welcome to the cockroach SQL interface.
# All statements must be terminated by a semicolon.
# To exit: CTRL + D.
#
# Server version: CockroachDB CCL v2.0.1 (x86_64-apple-darwin13, built 2018/04/23 18:35:36, go1.10) (same version as client)
# Cluster ID: a0ef8e47-5152-4836-bcb4-ad6261c9a1a6
#
# Enter \? for a brief introduction.
#
warning: no current database set. Use SET database = <dbname> to change, CREATE DATABASE to make a new database.
root@:26257/>

创建数据库

root@:26257/> CREATE DATABASE bank;
CREATE DATABASE

Time: 5.886953ms

创建数据表

root@:26257/> CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
CREATE TABLE

Time: 6.244176ms

插入数据

root@:26257/> INSERT INTO bank.accounts VALUES (1, 1000.50);
INSERT 1

Time: 68.896644ms

查询数据

root@:26257/> SELECT * FROM bank.accounts;
+----+---------+
| id | balance |
+----+---------+
|  1 | 1000.50 |
+----+---------+
(1 row)

Time: 1.762224ms

退出

root@:26257/> \q
[abeffect@note cockroach-v2.0.1.darwin-10.9-amd64]$

停止

先停止第一个集群:Ctrl + C
再停止后面两个集群

来源

评论

发表评论

validate