This page shows you how to deploy a CockroachDB cluster on CockroachCloud Free (beta), connect to it using the CockroachDB built-in SQL client, and run sample SQL statements.
To run CockroachDB on your local machine instead, see Start a Local Cluster.
Before you begin
If you haven't already, sign up for a CockroachCloud account.
Step 1. Create a free cluster
- Log in to your CockroachCloud account.
- On the Clusters page, click Create Cluster.
On the Create your cluster page, select the Free Plan.
Note:This cluster will be free forever.
Click Create your free cluster.
Your cluster will be created in approximately 20-30 seconds.
Step 2. Set up your cluster connection
Once your cluster is created, the Connection info modal displays. Use the information provided in the modal to set up your cluster connection for the SQL user that was created by default:
- Click the name of the
cc-ca.crt
to download the CA certificate to your local machine. Create a
certs
directory on your local machine:copy$ mkdir certs
Move the downloaded
cc-ca.crt
file to thecerts
directory:copy$ mv <path>/<to>/cc-ca.crt <path>/<to>/certs
For example:
copy$ mv Users/maxroach/Downloads/cc-ca.crt Users/maxroach/certs
Copy the connection string provided, which will be used in the next steps (and to connect to your cluster in the future).
Warning:This connection string contains your password, which will be provided only once. If you forget your password, you can reset it by going to the SQL Users page.
Step 3. Use the built-in SQL client
You can now connect to your cluster using CockroachDB's built-in SQL client:
If you have not done so already, download the CockroachDB binary:
copy$ curl https://binaries.cockroachdb.com/cockroach-v20.2.3.darwin-10.9-amd64.tgz \ | tar -xJ
copy$ wget -qO- https://binaries.cockroachdb.com/cockroach-v20.2.3.linux-amd64.tgz \ | tar xvz
copy$ brew install cockroachdb/tap/cockroach
Copy the binary into the
PATH
so it's easy to run the SQL client from any location:copy$ cp -i cockroach-v20.2.3.darwin-10.9-amd64/cockroach /usr/local/bin/
copy$ sudo cp -i cockroach-v20.2.3.linux-amd64/cockroach /usr/local/bin/
In your terminal, connect to your cluster using the connection string:
copy$ cockroach sql --url 'postgres://<username>:<password>@free-tier.gcp-us-central1.cockroachlabs.cloud:26257/<cluster_name>.defaultdb?sslmode=verify-full&sslrootcert=<certs_dir>/cc-ca.crt'
In the connection string copied from the Connection info modal, your username, password and cluster name are pre-populated. Replace the
<certs_dir>
placeholder with the path to thecerts
directory that you created in Step 2. For example:copy$ cockroach sql --url 'postgres://maxroach:password123@free-tier.gcp-us-central1.cockroachlabs.cloud:26257/test-cluster.defaultdb?sslmode=verify-full&sslrootcert=/Users/maxroach/certs/cc-ca.crt'
Using the built-in SQL client, you can now run CockroachDB SQL statements:
copy> CREATE DATABASE bank;
copy> CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
copy> INSERT INTO bank.accounts VALUES (1, 1000.50);
copy> SELECT * FROM bank.accounts;
id | balance -----+---------- 1 | 1000.50 (1 row)
To exit the SQL shell:
copy> \q
What's next?
Learn more:
- Use the built-in SQL client to connect to your cluster and learn CockroachDB SQL.
- Create and manage SQL users.
- Build a "Hello World" app with the Django framework, or install another client framework for your preferred language.
- Explore our sample apps for examples on how to build simple "Hello World" applications using CockroachCloud Free (beta).