Install CockroachDB on Ubuntu 16.04.

Install CockroachDB on Ubuntu 16.04.

Every time I read an article about "10 Reasons You Should Start a Blog", there is always something about "learning new skills", and it sounds obvious but it's true. Lately, I'm always thinking about things to write about which makes me search more ... until I find something that gets my attention.

One of the things I discovered while searching for new articles for DBplatz is CockroachDB. (After all ... this is a database related blog).

White robot human features
Photo by Alex Knight / Unsplash

And after reading some articles I joined a webinar called "Deploy a Cloud-Native Database on Kubernetes With CockroachDB", which I actually enjoyed, and thought, well let's give it a try.

So I read the documentation and actually you can actually follow these steps on their website but this is one page - one node basic guide.

wget -qO- | tar  xvz
Download and extract the binary
$ sudo cp -i cockroach-v19.2.5.linux-amd64/cockroach /usr/local/bin/
[sudo] password for dbplatz:
Copy the binary into PATH
$ sudo cockroach start \
> --insecure \
> --store=node1 \
> --listen-addr=localhost:26257 \
> --http-addr=localhost:8080 \
> --join=localhost:26257,localhost:26258,localhost:26259 \
> --background
Start the cluster (insecure).
* - 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:
* INFO: initial startup completed.
* Node will now attempt to join a running cluster, or wait for `cockroach init`.
* Client connections will be accepted after this completes successfully.
* Check the log file(s) for progress.
You will see this output
$ cockroach init --insecure --host=localhost:26257

Cluster successfully initialized
Initialization of CockroachDB
dbplatz@ubusrvroach:/usr/local/bin$ cockroach sql --insecure --host=localhost:26257
So now we can connect to it
# Welcome to the CockroachDB SQL shell.
# All statements must be terminated by a semicolon.
# To exit, type: \q.
# Server version: 
# CockroachDB CCL v19.2.5 (x86_64-unknown-linux-gnu, 
# built 2020/03/16 18:27:12, go1.12.12) (same version as client)
# Cluster ID: 49504dc9-1fea-4728-85e5-7825b24d657c
# Enter \? for a brief introduction.
root@localhost:26257/defaultdb> CREATE DATABASE bank;

Time: 17.402244ms

CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);

Time: 64.715061ms

INSERT INTO bank.accounts VALUES (1, 1000.50);

Time: 18.856247ms

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

Time: 934.002µs

root@localhost:26257/defaultdb> \q
and execute some basics commands.

According to the webinar it is really easy to add new nodes to the cluster so in the next post we will try that and more.

Want to thank me?

Buy Me A Coffee